急求,如何用vb读取txt文件并保存到二维数组里,如所给的数据 谢谢

0.374 8:14
0.372 8:14
0.374 8:15
0.372 8:15
-3.969 8:25
-3.97 8:26
-3.972 8:26
-3.971 8:26
0.328 8:34
0.334 8:35
0.325 8:35
0.326 8:35
-3.947 8:42
-3.951 8:43
-3.946 8:43
-3.946 8:43
-5.17 8:52
-5.176 8:53
能不能写详细点,我是编程小白

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
温馨提示:内容为网友见解,仅供参考
无其他回答
相似回答