请问如何用VB如何读取文件里某部分的数据(数据分行,分列),然后将读取的数据显示在listbox里。

2024-12-12 13:42:02
推荐回答(1个)
回答1:

Private Sub Command1_Click()
Dim inputdata$, datastring$
Open App.Path & IIf(Right(App.Path, 1) = "\", "", "\") & "data.txt" For Input As #1
Do While Not EOF(1)
Line Input #1, inputdata
datastring = datastring & inputdata & vbCrLf
Loop
List1.Clear
tempdata = Split(datastring, Chr(13) + Chr(10))
For I = 0 To UBound(tempdata) - 1
tempdata(I) = Right(tempdata(I), Len(tempdata(I)) - 8)
List1.AddItem tempdata(I)
Next
End Sub

'data.txt 在与该程序同目录下