Private Sub Command1_Click() '读文件
Open "d:a.txt" For Input As #1
Dim Lines As String
Dim NextLine As String
Dim i As Integer
Do While Not EOF(1)
On Error Resume Next
Line Input #1, NextLine
Lines = Lines & NextLine & Chr(13) & Chr(10)
Loop
Close #1
Text1.Text = Lines
End Sub
Private Sub Command2_Click() '写文件
Open "d:a.txt" For Output As #1
Print #1, Text1.Text
Close #1
End Sub
'如果要处理的是程序目录所在的a.txt那么应该是这样写:
'Open app.path+"/a.txt" For Input As #1
Open "d:a.txt" For Input As #1
Dim Lines As String
Dim NextLine As String
Dim i As Integer
Do While Not EOF(1)
On Error Resume Next
Line Input #1, NextLine
Lines = Lines & NextLine & Chr(13) & Chr(10)
Loop
Close #1
Text1.Text = Lines
End Sub
Private Sub Command2_Click() '写文件
Open "d:a.txt" For Output As #1
Print #1, Text1.Text
Close #1
End Sub
'如果要处理的是程序目录所在的a.txt那么应该是这样写:
'Open app.path+"/a.txt" For Input As #1
本文介绍了一个使用VBScript进行文件读写的示例代码,包括打开文件、读取文件内容到字符串变量、关闭文件的过程,并展示了如何将文本框中的内容写回到文件中。

149

被折叠的 条评论
为什么被折叠?



