VB读取txt文本问题

来源:百度知道 编辑:UC知道 时间:2024/07/16 15:28:21
Private Sub Command3_Click()
Dim Lines As String
Dim NextLine As String
On Error GoTo err
CommonDialog1.InitDir = "App.Path"
CommonDialog1.Filter = "*.txt|*.txt"
CommonDialog1.ShowOpen
Open CommonDialog1.FileName For Input As #4
Do While Not EOF(1)
On Error Resume Next
Line Input #4, NextLine
Lines = Lines & NextLine & Chr(13) & Chr(10)
Loop
Close #4
Text1.Text = Lines
err:
End Sub
为什么显示不到在text文本框

do while not eof(4)

Open ... For Output As #4 才对

For Input 一次性写入覆盖
For Output 读取
For Append 追加内容

eof()中的数字要与文件号一致.

Open CommonDialog1.FileName For Input As #4
Do While Not EOF(4)
On Error Resume Next
Line Input #4, NextLine
Lines = Lines & NextLine & Chr(13) & Chr(10)
Loop
Close #4