如何用VB读取txt或dat文件?

2024-11-27 09:31:53
推荐回答(1个)
回答1:

Dim sContent As String '定义变量储存读入的数据
Dim sData() As String '定义数组用于储存分割后的数据
Open "d:\box.prt.log" For Input As #1 '打开文件,标记为1
Do While Not EOF(1) '循环读取直至尾部
Line Input #1, sContent
If InStr(sContent, "=") <> 0 Then
sData = Split(sContent, "=", -1) '拆分读取出的字符串,中间的“=分割标记
Dim i As Integer
For i = LBound(sData) To UBound(sData)
MsgBox sData(i)
Next
End If
Loop
Close #1