如何用VB读取TXT文件中的数据,TXT文件的每个数据用逗号分开,但字符长度不同.

高分请分析下,如何用VB读取TXT文件中的数据,TXT文件的每个数据用逗号分开,但字符长度不同.
最新回答
欲往

2024-11-03 09:47:12

用Split Dim s As String
Dim sp() As String
Open "c:\1.txt" For Input As #1 '比如打开"c:\1.txt",内容是:5,56,5855,455665
While Not EOF(1)
Line Input #1, s
Wend
Close #1
sp = Split(s, ",")'执行后sp的元素内容就分别是5、56、5855、455665
一抹晚夏

2024-11-03 10:28:52

Private Sub Command1_Click()
Dim a As String
Open "c:\2.txt" For Input As #1
Do Until EOF(1)
Line Input #1, a
a = Right(a, Len(a) - InStr(a, ","))
a = Left(a, InStr(a, ",") - 1)
Text2.Text = Text2.Text & a & vbCrLf
Loop
Close #1
End Sub