vb如何读取txt文本,并逐行显示在label里面

2025-02-23 17:43:27
推荐回答(1个)
回答1:

Private a() As String
Private idx As Integer
Private Sub Command1_Click()
Dim i As Integer
ReDim Preserve a(0 To 0) As String
Open "c:\1.txt" For Input As #1
While Not EOF(1)
Line Input #1, a(i)
i = i + 1
ReDim Preserve a(0 To i) As String
Wend
Close #1
Timer1.Enabled = True
Timer1.Interval = 10000
idx = 0
Call Timer1_Timer
End Sub

Private Sub Timer1_Timer()
Label1.Caption = a(idx)
idx = idx + 1
If idx > UBound(a) Then
Timer1.Enabled = False
Timer1.Interval = 0
End If
End Sub