Option Explicit Dim flag As BooleanPrivate Sub Command1_Click() Dim strLine As String, strCol() As String Dim i As Long, n As Long Timer1.Interval = 5000 Timer1.Enabled = True
Label1 = "Reading ..."
Open "c:\test\test1.txt" For Input As #1 Do Until EOF(1) Line Input #1, strLine strCol = Split(strLine, ",")
n = UBound(strCol)
For i = 0 To 7 If i <= n Then Text1(i) = strCol(i) Else Text1(i) = "" End If Text1(i).Refresh Next i
Do Until flag DoEvents Loop
flag = False Loop Close #1
Timer1.Enabled = False
Label1 = "Finished"
End SubPrivate Sub Timer1_Timer() flag = True End Sub
具体到“读文件”,有很多种方案去实现。你的“每行8个字段”,那你得说清楚数据格式啊!
要不然,鬼知道你的是什么样的、要怎样才能“分成8个”呢!要把数据“放到 TextBox 中”,用控件数组的话,可以For循环搞定;
就算是独立控件、控件名没规律,也不过8个嘛,直接硬写8条赋值语句也无妨……
Dim flag As BooleanPrivate Sub Command1_Click()
Dim strLine As String, strCol() As String
Dim i As Long, n As Long Timer1.Interval = 5000
Timer1.Enabled = True
Label1 = "Reading ..."
Open "c:\test\test1.txt" For Input As #1
Do Until EOF(1)
Line Input #1, strLine
strCol = Split(strLine, ",")
n = UBound(strCol)
For i = 0 To 7
If i <= n Then
Text1(i) = strCol(i)
Else
Text1(i) = ""
End If
Text1(i).Refresh
Next i
Do Until flag
DoEvents
Loop
flag = False
Loop
Close #1
Timer1.Enabled = False
Label1 = "Finished"
End SubPrivate Sub Timer1_Timer()
flag = True
End Sub
都还没搞明白吧…………