我有一个包含以下行的文本文件:
11/01/2013 00:57:59 01 00 0238 POST UNIT ID
11/01/2013 00:58:07 01 80 0136 PRE UNIT ID
11/01/2013 00:58:16 01 80 0136 PRE UNIT ID
11/01/2013 00:58:22 01 00 0238 POST UNIT ID
我想阅读并在列表框中显示文本行,但test.txt是一个日志文件,每隔一秒就会在此文本中显示一条新行。使用我的方法与计时器相同的行重复。更新列表框以显示用文本文件编写的最新行的最佳解决方案是什么?我认为这是文本文件中的一种更新...
Private Sub Form_Load()
Timer1.Enabled = True
Timer1.Interval = 1000
End Sub
Private Sub Timer1_Timer()
filenum = FreeFile
filepath = "C:\test.txt"
Open filepath For Input As filenum
Do Until EOF(filenum)
Line Input #filenum, LineText
List1.AddItem LineText
Loop
Close filenum
End Sub
答案 0 :(得分:2)
在添加日志文件之前清除列表框
Private Sub Form_Load()
Timer1.Enabled = True
Timer1.Interval = 1000
End Sub
Private Sub Timer1_Timer()
filenum = FreeFile
filepath = "C:\test.txt"
Open filepath For Input As filenum
List1.Clear
Do Until EOF(filenum)
Line Input #filenum, LineText
List1.AddItem LineText
Loop
Close filenum
End Sub