读取txt的几个问题

来源:互联网 发布:网络焦虑症 编辑:程序博客网 时间:2024/05/01 22:13

点击第一个按钮 把C:/123.TXT 读取到 text1 要全部都能显示出来!我试过有的只能显示一行 或不能全部显示

第二个 按下第二个按钮 把 C:/321.TXT 读取到 text2 而且只读取文本的前20行... 后面的省略不读 

 

'text控件的multiline属性都设为true scrollbar属性设成2


'第一个按钮
Private Sub Command1_Click()
Open "c:/123.txt" For Input As #1
Dim Lines As String
Dim NextLine As String
Do Until EOF(1)
Line Input #1, NextLine
Lines = Lines & NextLine & Chr(13) & Chr(10)
Loop
Close #1

Text1.Text = Lines
End Sub
'第二个按钮
Private Sub Command2_Click()
Open "c:/321.txt" For Input As #1
Dim Lines As String
Dim NextLine As String
Dim i As Integer
For i = 1 To 20
On Error Resume Next
Line Input #1, NextLine
Lines = Lines & NextLine & Chr(13) & Chr(10)
Next i
Close #1
Text2.Text = Lines
End Sub