以下这段代码怎么修改才能显示全部的多行文本?
来源:百度知道 编辑:UC知道 时间:2024/06/06 20:00:47
Dim x As String
CommonDialog1.Filter = "文本文件(*.txt)|*.txt"
CommonDialog1.ShowOpen
Open CommonDialog1.FileName For Input As #1
Do While Not EOF(1)
Input #1, x
Text1.Text = x
Loop
Close #1
End Sub
加换行,字符串累加。
Private Sub Command1_Click()
Dim x As String
Dim y As String
CommonDialog1.Filter = "文本文件(*.txt)|*.txt"
CommonDialog1.ShowOpen
Open CommonDialog1.FileName For Input As #1
Do While Not EOF(1)
Input #1, x
y = y & x & vbcrlf
Loop
Close #1
Text1.Text = y
End Sub
'这是修改过的实现代码
Private Sub Command1_Click()
'Dim filepath As String
'filepath = openfile(Me)
'If filepath <> "" Then
'text1.Text = openfile(filepath)
'End If
CommonDialog1.Filter = "文本文件(*.txt)|*.txt"
CommonDialog1.ShowOpen
text1.Text = openfile(CommonDialog1.FileName) '直接调用openfile函数即可返回文本文件的所有内容 包括换行
End Sub
Public Function openfile(ByVal filepath As String) As String
Dim s As String
Open filepath For Input As #1
While Not EOF(1)
Line Inpu