I'm trying to fetch the tab delimited text file into arrays, I already know how to read that text file into spreadsheet, the following is my code which works perfectly:
While Not EOF(iFile)
Line Input #iFile, LineText
Dim arr
arr = Split(CStr(LineText), vbTab)
For j = 1 To UBound(arr)
Worksheets("TxtRead").Cells(i, j).Value = arr(j - 1)
Next
i = i + 1
Wend
Close #iFile
So instead of fetching values to the spreadsheet, I would like to write them to a two-dimentional array, how would I do that? I have a code below, but it doesn't work:
Dim MemoryArray()
While Not EOF(iFile)
Line Input #iFile, LineText
Dim arr
arr = Split(CStr(LineText), vbTab)
For j = 1 To UBound(arr)
Worksheets("TxtRead").Cells(i, j).Value = arr(j - 1)
MemoryArray(i - 1, j - 1) = arr(j - 1)
Next
i = i + 1
Wend
Close #iFile
Thanks for any inputs and thoughts!
Redim Preserveon the second dimension of a 2-D array. Also how do you handle cases where different lines have different numbers of elements. If you know up-front that all lines will have the same number of items then that helps. How large (# of rows/columns) are your files going to be?