vb读取文本

来源:百度知道 编辑:UC知道 时间:2024/05/31 04:27:55
Private Sub Command1_Click()
Open App.Path & "\ab.txt" For Output As #1
Print #1, Text1.Text
Close #1
End Sub

Private Sub Form_Load()
Dim str1 As String
Text1.Text = ""
Open App.Path & "\abc.txt" For Input As #1
Do While Not EOF(1)
Input #1, str1
Text1.Text = Text.Text + str1
Loop
Close #1
End Sub

这是VB读取文本的代码,有什么错误的吗?
执行总说找不到文件,有这两个文件的
那按钮1要怎么读取文件啊?谢谢帮忙了

你要先保存那个工程到abc.txt那个目录先


Text1.Text = Text.Text + str1 (这里少了个1吧?还是你还有个text重新命名了个名字呢)

Private Sub Command1_Click()
Open App.Path & "\ab.txt" For Output As #1
str1 = Text1.Text
Print #1, str1
Close #1
End Sub

Private Sub Form_Load()
Dim str1 As String
Text1.Text = ""
Open App.Path & "\abc.txt" For Input As #1
Do While Not EOF(1)
Line Input #1, str1
Text1.Text = Text1.Text + str1
Loop
Close #1
End Sub