ОПИСАНИЕ:
У меня есть 10 текстовых файлов. И я хочу прочитать их в двухмерном массиве. Каждый файл выглядит так и количество строк варьируется. В этом текстовом файле 5 строк, но в других текстовых файлах может быть больше или меньше 5 строк.
No. Location(ft) Mix Near Far Comp. Height(ft) B(in) D(in) Angle(degrees)
1 (0.8127,8.66) 35 MPa true true true 9.17 10 36 0
2 (0.8333,60.67) 35 MPa true true true 9.17 10 36 0
3 (0.8333,80.42) 35 MPa true true true 9.17 10 36 0
4 (14.19,26.22) 35 MPa true true true 9.17 10 24 0
Первое измерение массива будет содержать каждую строку текстового файла. Вторым измерением массива будет каждый текстовый файл.
Так как то так
Redim TotalArray (от 1 до 1000, от 1 до 10)
1000 определенно больше, чем количество строк, которые у меня есть. 10 для 10 текстовых файлов
ЗАКЛЮЧИТЕЛЬНАЯ ЦЕЛЬ:
Последним шагом будет дальнейшее разделение столбцов каждого текстового файла. Другими словами, мне может понадобиться трехмерный массив? Однако сначала я тестирую коды для двумерного массива. Я просто заявляю о своей конечной цели на случай, если мой подход окажется бесполезным, и вы, ребята, можете предложить что-то лучшее.
Мои коды следующие:
Sub GetFile()
'Loop through all files in a folder
Dim fileName As String
fileName = Dir("C:\*.txt")
Dim arNames() As String
Dim myCount As Integer
myCount = -1
Do Until fileName = ""
myCount = myCount + 1
ReDim Preserve arNames(myCount)
arNames(myCount) = fileName
fileName = Dir
Loop
' Finish reading file names into arNames.
' This part of the code is successful
Dim TextArray()
Dim x As Double
Dim k As Integer
Dim UBound_arNames As Integer
UBound_arNames = UBound(arNames())
ReDim TotalArray(0 To 1000, 0 To UBound_arNames)
For k = 0 To 2
Open "C:\" & arNames(k) For Input As #1
' Open file.
Do While Not EOF(1) ' Loop until end of file.
ReDim Preserve TextArray(x) ' Preserve the Array
Line Input #1, TextArray(x) ' Read line into variable.
TotalArray(x, k) = TextArray(x)
' The bug is the above line. TextArray(x) works fine but it cannot be
' written to TotalArray(x, k). I need the second dimension k to make
' the second dimension contains the number of text files that I have
' I know the bug is here because MsgBox TextArray(0) works
' but MsgBox TotalArray(0,0) or any other cell prints nothing
x = x + 1 ' increment array count
Loop
Close #1 ' Close file.
MsgBox TextArray(0)
MsgBox TextArray(1)
Next k
End Sub
Пожалуйста, помогите мне