vb从txt中读取字符串

来源:百度知道 编辑:UC知道 时间:2024/05/28 05:22:15
txt字符串的形式
03090104093218

12090104180259
两行之间有空格,将上面的字符串读到二维数组中。用循环,因为有很多行,谢谢大家了。

Private Sub Command1_Click()
Dim str(1 To 10, 1 To 2) As String ' 数组大小可以设置大些,得看你文件中有多少数据。
Dim tm As String '存放空行的 无用变量
Dim i As Integer
On Error Resume Next
Open "d:\cc.txt" For Input As #1 '自己更改文件路径
i = 1
Do While Not EOF(1)
Line Input #1, str(i, 1)
Line Input #1, tm
Line Input #1, str(i, 2)
Line Input #1, tm
Print str(i, 1), str(i, 2)
i = i + 1
Loop
Close #1

End Sub

在数据形式如下:(两个一组)
03090104093218

12090104180259

03090104093217

22090104180259

03090104093216

32090104180259

03090104093215

42090104180259
的文本文件中运行成功

Private Sub Form_Load()
Dim str() As String
Open App.Path & "\cc.txt" For Input As #1
Do While Not EOF(1)
Line Input #1, str
Loop
Close #1
end sub