把代码作如下修改即可,不用做引用
Private Sub Command1_Click()
Dim fso, txtfile, fil, ts, s
Set fso = CreateObject("scripting.filesystemobject")
Set txtfile = fso.createtextfile("c:\testfile.txt", True)
txtfile.Close
MsgBox "正在写入文件"
Set fil = fso.getfile("c:\testfile.txt")
Set ts = fil.openastextstream(2)
ts.write "hello world"
ts.Close
Set ts = fil.openastextstream(1)
s = ts.readline
MsgBox s
ts.Close
End Sub
请教各位大哥
小弟使用file system objects 读取文件,要从一个文本文件中读取数据,程序如下:
Private Sub Command1_Click()
Dim fso As New filesystemobject, txtfile, fil As File, ts As textstream
Set txtfile = fso.createtextfile("c:\testfile.txt", True)
MsgBox "正在写入文件"
Set fil = fso.getfile("c:\testfile.txt")
Set ts = fil.openastextstream(forwriting)
ts.write "hello world"
ts.Close
Set ts = fil.openastextstream(forreading)
s = ts.readline
MsgBox s
ts.Close
End Sub
程序运行后出现如下提示:
Private Sub Command1_Click()
CommonDialog1.InitDir = "d:\"
CommonDialog1.FileName = "123.txt"
CommonDialog1.Filter = "文本文件(*.txt)"
CommonDialog1.ShowSave
End Sub
请教各位大哥
小弟使用file system objects 读取文件,要从一个文本文件中读取数据,程序如下:
Private Sub Command1_Click()
Dim fso As New filesystemobject, txtfile, fil As File, ts As textstream
Set txtfile = fso.createtextfile("c:\testfile.txt", True)
MsgBox "正在写入文件"
Set fil = fso.getfile("c:\testfile.txt")
Set ts = fil.openastextstream(forwriting)
ts.write "hello world"
ts.Close
Set ts = fil.openastextstream(forreading)
s = ts.readline
MsgBox s
ts.Close
End Sub
程序运行后出现如下提示:
'新建一个txt文件
Dim objCreateTxtFile As Object
Dim a
Set objCreateTxtFile = CreateObject("Scripting.FileSystemObject")
Set a = objCreateTxtFile.CreateTextFile(文件路径, TXT名称, True)
a.Close
Set objCreateTxtFile = Nothing
' 写入txt文件
Open 刚才创建的TXT名称全路径 For Binary As #1
Put #1, , 要写的内容
Close #1