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

2024年11月18日 06:30
有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