I am trying to fill an array using a loop in VB. It basically read a .txt file and store all the line in an array. Im getting this error. "Array is used before it has been assigned values".
Dim fileEntries As String() = Directory.GetFiles(folderDIR, "*.txt")
Dim fileName As String
Dim fileReader As StreamReader
Dim strReadFile As String
Dim arrLines() As String
Dim i As Integer = 0
For Each fileName In fileEntries
fileReader = File.OpenText(fileName)
Do Until fileReader.Peek = -1
strReadFile = fileReader.ReadLine()
arrLines(i) = strReadFile
i += 1
Loop
Next
Is there any way I could do this, without pre-defining length of the array? I want the length of array to be number of lines in txt files. Hope i explained this well. Thank you in advance.