怎么在VB里显示文本的内容

来源:百度知道 编辑:UC知道 时间:2024/06/23 17:28:43
我想用一个command和一个textbox显示一个文本文档里的内容就是点一下command文本里的内容就显示在textbox里了

Private Sub Command1_Click()
Dim a As String
Text1.Text = ""
Open "c:\1.txt" For Input As #1 '1.txt是文件名
While Not EOF(1)
Line Input #1, a
Text1.Text = Text1.Text & a & vbCrLf
Wend
End Sub

你可以搜索下vb的txt读写教程或原程序
学习下
很简单的

Private Sub Command1_Click()
Dim s As String
Open "c:\123.txt" For Input As #1
s = Input(LOF(1), #1)
text1 = s
Close #1
End Sub

这个适用于西文,如果是纯中文,把lof(1)换成lof(1)/2
如果是中西文混合,适用下面的过程:
Private Sub Command1_Click()
Dim s As String
Open "c:\123.txt" For Input As #1
text1 = ""
Do While Not EOF(1)
Line Input #1, s
text1 = text1 & vbCrLf & s
Loop
Close #1
End Sub