求VB读跟写文本文件方法?
求VB读跟写文本文件方法?
[解决办法]
二进制读,二进制写。
Option Explicit
Dim FileByte() As Byte, FileNumber As Long
'读文本文件
Private Sub Command1_Click()
FileNumber = FreeFile
Open "c:\FFinit.txt" For Binary As #FileNumber
ReDim FileByte(LOF(FileNumber) - 1)
Get #FileNumber, , FileByte
Debug.Print StrConv(FileByte, vbUnicode)
End Sub
'写文本文件
Private Sub Command2_Click()
FileNumber = FreeFile
Open "c:\FFinit_1.txt" For Binary As #FileNumber
Put #FileNumber, , "CSDN全球最大中文社区网站"
End Sub
Private Sub Form_Load()
Command1.Caption = "读文本文件"
Command2.Caption = "写文本文件"
End Sub
'读文本文件
Private Sub Command1_Click()
FileNumber = FreeFile
Open "c:\FFinit.txt" For Input As #FileNumber
Input #FileNumber, varlist
Debug.Print varlist
Line Input #FileNumber, varname
Debug.Print varname
End Sub
'写文本文件
Private Sub Command2_Click()
FileNumber = FreeFile
Open "c:\FFinit_1.txt" For Output As #FileNumber
Print #FileNumber, "CSDN全球最大中文社区网站"
Write #FileNumber, outputlist
End Sub