读取TXT文件存放到二维数组中
txt文本
1 2 3 4
a b c d
行数不固定 列数为6
我写的代码,求大神帮忙改改
Private Sub getTxt()
Dim Str As String
Dim sumStr(10000,5),tmp() As String
Dim n As Integer
Open "D:\abc.txt" For Input As #1
Do Unitl EOF(1)
Line Input #1,Str
tmp=Split(Str,Char(9))
For i=0 to 5
sumStr(n,i)=tmp(i)
next i
n=n+1
Loop
Close #1
End Sub
[解决办法]
ReDim 为数组变量重新分配存储空间。可选项修饰符 Preserve 当仅更改最后一个维度的大小时,用来保留现有数组中的数据。
Dim sumStr() as string
redim sumstr(5,0)
Do Unitl EOF(1)
Line Input #1,Str
tmp=Split(Str,Char(9))
For i=0 to 5
sumStr(i,n)=tmp(i)
next i
n=n+1
redim Preserve sumStr(5,n)
Loop
Close #1