vb 怎么读写文本文件
Private Sub CmdRead_Click() Dim fsoTest As New FileSystemObject, file1 As File, ts As TextStream,
s As String
Set file1 = fsoTest.GetFile(“C:\testfile.txt")
Set ts = file1.OpenAsTextStream(ForReading)
'读取一行
s = ts.ReadLine
MsgBox s
ts.Close
End Sub
Private Sub CmdWrite_Click()
Dim txtfile As File, ts As TextStream
Set txtfile = fsoTest.GetFile(“c:\testfile.txt")
Set ts = txtfile.OpenAsTextStream(ForWriting)
'使用Write方法写入一行。
ts.Write (“This is only a Test")
' 写入一行带有换行符的文本。
ts.WriteLine (“Testing 1, 2, 3.")
' 向文件中写入三个换行符。
ts.WriteBlankLines (3)
ts.Close
End Sub
上面这段代码我在执行的时候 点击 CmdWrite_Click,系统就说 编译错误 用户定义类型未定义,错误停留在
Dim txtfile As File 这一行
如果点击 CmdRead_Click 系统就说 编译错误 用户定义类型未定义,错误停留在
Dim fsoTest As New FileSystemObject 这一行,是怎么回事啊