VB读取TXT文件的问题!!!

来源:百度知道 编辑:UC知道 时间:2024/05/13 19:50:57
我要在点击第一个按钮 把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

全部显示:

Option Explicit
Dim str1 As String
Dim str As String
Dim i As Integer
Private Sub Command1_Click()
CommonDialog1.ShowOpen
Text1 = ""
i = 0
Open CommonDialog1.FileName For Input A