1、vb6新建文本文件有很多种办法。
2、以下示例使用open语句的output方式创建d:盘根目录下的TESTFILE.TXT文本文件。
Private Sub Command1_Click()
Open "d:\TESTFILE.TXT" For Output As #1
Print #1, "Hello world."
Close #1
End Sub
sub command1_click()
filename$="c:\" & format(now, "yyyymm") & ".txt"
if len(dir(filename)) then msgbox "文件存在":exit sub
open filename for binary as #1
close #1
end sub
Private Sub Command1_Click()
Dim nyr As String
On Error GoTo userERR
nyr = Mid(Date$, 1, 4) & Mid(Date$, 6, 2) & Mid(Date$, 9, 2)
Open "c:\" & nyr & ".txt" For Input As #1
Close
MsgBox ("文件存在")
userERR:
Open "c:\" & nyr & ".txt" For Output As #1
Close
End Sub
Dim FileNum As Integer
Dim FileName As String
FileNum = FreeFile()
FileName = "c:\" & Format(Now, "YYYYMMDD") & ".txt"
If Dir(FileName) <> "" Then
MsgBox "文件存在"
Else
Open FileName For Output As FileNum
Close FileNum
End If
Dim FileNum As Integer
Dim FileName As String
FileNum = FreeFile()
FileName = "c:\" & datetime.now.todate & ".txt"
If Dir(FileName) <> "" Then
MsgBox "文件存在"
Else
Openfile( filenum,openmode.open)
write(file,"filename.txt","")
Closefile(FileNum)
End If