Private Sub Command1_Click()
Dim i As Integer
'因为数据里有冒号,所以采用字符串格式
Dim d() As String
Dim LStr() As String
Dim H As Integer
Dim L() As String
'先将数据读取到动态数组LStr(),假设文本文件存放于与程序文件同一个文件夹
Open App.Path & "\data.txt" For Input As #1 '以读的方式打开文件
H = 0
Do While Not EOF(1) ' 循环至文件尾
H = H + 1
ReDim Preserve LStr(H) As String
Line Input #1, LStr(H) '读入一行
Loop
Close #1 ' 关闭文件。
'重新声明数组的规模
ReDim d(H, 2) As String
'把数据,从LStr读到d
For i = 1 To H
'去除多余的空格,只留一个空格
Do While InStr(LStr(i), " ") <> 0
LStr(i) = Replace(LStr(i), " ", " ")
Loop
L = Split(LStr(i), " ")
d(i, 1) = L(0)
d(i, 2) = L(1)
Next i
'将二维数组输出到窗体
For i = 1 To H
Print d(i, 1), d(i, 2)
Next i
End Sub
温馨提示:内容为网友见解,仅供参考