VB点击按钮1次,读取文本1行,点击第2次,读取第2行,依次往下.... ... 直到全部读完。

2024-11-18 06:30:01
推荐回答(1个)
回答1:

Dim text As String
Dim i As Integer
Dim a() As String
Private Sub Command1_Click()

text = ""
CommonDialog1.FileName = ""
CommonDialog1.Filter = "文本文件.txt|*.txt"
CommonDialog1.ShowOpen

If CommonDialog1.FileName <> "" Then
Open CommonDialog1.FileName For Input As #1
Do While Not EOF(1)
Line Input #1, demo
text = text & vbCrLf & demo
Loop
End If
Close #1

End Sub

Private Sub Command2_Click()
a = Split(text, vbCrLf)
If i < UBound(a) Then
Text1.text = i + 1
Text2.text = a(i + 1)
Clipboard.Clear
Clipboard.SetText (Text2.text)
i = i + 1
End If
End Sub