VB怎样读取和修改txt中文数据?

用VB修改和读取当前目录下的a.txt:加载时Text1显示a.txt的文本,单击Command1时,将Text1的文本改入a.txt里。
我做了一次,但不能读取中文,当文本带有中文时,a.txt里对应的那一行就变成空的了,怎么办?

Private Sub FORM_LOAD()'把数据读到文本框里
Dim R As String
Open App.Path & "\" & "A.TXT" For Input As #1
Do While EOF(1) = False
Line Input #1, R
Text1.Text = Text1.Text & vbCrLf & R
Loop
Close #1
End Sub

Private Sub COMMAND1_click() ‘写入改变的数据
Open App.Path & "\" & "A.TXT" For Output As 1
Print #1, Text1.Text
Close #1
End Sub
经过验证通过运行,注意这里的A.TXT的路径你可以自己设定,呵呵
温馨提示:答案为网友推荐,仅供参考
第1个回答  2011-03-29
Private Sub Command1_Click() '读
Text1.Text = ""
Open "test.txt" For Input As #1
Do While Not EOF(1)
Line Input #1, temp
Text1.Text = Text1.Text & temp & vbCrLf
Loop
Close #1
End Sub

Private Sub Command2_Click() '写
Open "test.txt" For Output As #1
Print #1, Text1.Text
Close #1
End Sub
相似回答