VB6.0 文件日志读取
1 Private Sub ReadWriteLog() 2 3 Dim fsObj As New Scripting.FileSystemObject 4 Dim fileTextStream As Scripting.TextStream 5 Dim fileText As String 6 Dim filePath As String 7 Dim context As String 8 Dim flag As Long 9 Dim totalLen As Long 10 11 filePath = "C:\Logfile20160115.txt" 12 13 If Not fsObj.FileExists(filePath) Then 14 MsgBox "No File Exist" 15 Exit Sub 16 End If 17 18 Set fileTextStream = fsObj.OpenTextFile(filePath) 19 ''fileText = fileTextStream.ReadAll ''read all context 20 21 While Not fileTextStream.AtEndOfLine 22 context = fileTextStream.ReadLine 23 totalLen = Len(context) 24 flag = InStrRev(context, ":") 25 context = Right$(context, totalLen - flag - 1) 26 27 MsgBox "Message value : " & context 28 Wend 29 30 fileTextStream.Close 31 32 Set fileTextStream = Nothing 33 Set fsObj = Nothing 34 35 End Sub
同样也可以实现一次全部读取文件内容;