急求,如何用vb读取txt文件并保存到二维数组里,如所给的数据 谢谢
0.3748:140.3728:140.3748:150.3728:15-3.9698:25-3.978:26-3.9728:26-3.9718:260.3288:340...
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
能不能写详细点,我是编程小白 展开
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
能不能写详细点,我是编程小白 展开
1个回答
展开全部
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
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
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询