小弟我写了一段程序,将消息记录写入TXT文件,但是发现文件写到24K就不在写了,把文件删除了也不行!怎么办,谢谢!!
Private Sub Write_LOG(msg As String)
Dim temp
Dim Str As String
Dim Date_Str As String
Dim LOG_Str As String
Date_Str = Format(Now(), "yyyy-mm-dd")
Str = Format(Now(), "yyyy-mm-dd hh:mm:ss ") & Trim(msg)
FileNum = FreeFile
FileName = Trim(App.Path & "\" & Date_Str & ".txt")
If Dir(FileName) = "" Then
'------Create File--------------------
Call Create_LOG_File
End If Open FileName For Input As #1 ' 打开文件。
Do While Not EOF(1) ' 循环至文件尾。
Line Input #1, temp ' 读入一行数据并将其赋予某变量。
LOG_Str = LOG_Str + temp + vbCrLf
Loop
Close #1 ' 关闭文件。
Open FileName For Output As FileNum
Print #FileNum, LOG_Str + Str Close #FileNumEnd Sub
Private Sub Write_LOG(msg As String)
Dim temp
Dim Str As String
Dim Date_Str As String
Dim LOG_Str As String
Date_Str = Format(Now(), "yyyy-mm-dd")
Str = Format(Now(), "yyyy-mm-dd hh:mm:ss ") & Trim(msg)
FileNum = FreeFile
FileName = Trim(App.Path & "\" & Date_Str & ".txt")
If Dir(FileName) = "" Then
'------Create File--------------------
Call Create_LOG_File
End If Open FileName For Input As #1 ' 打开文件。
Do While Not EOF(1) ' 循环至文件尾。
Line Input #1, temp ' 读入一行数据并将其赋予某变量。
LOG_Str = LOG_Str + temp + vbCrLf
Loop
Close #1 ' 关闭文件。
Open FileName For Output As FileNum
Print #FileNum, LOG_Str + Str Close #FileNumEnd Sub
Open "l:\123.Log" For Append As #1
Print #1, "abcdefg"
Close #1
Open FileName For Append As #1
*****************
Dim LOG_Str As String局限了大小
字符串型 String 1~65535字节
Open FileName For Append As #1 ' 打开文件。
Print #1, Str
Close #1 ' 关闭文件。
最好不要用 Basic 关键字(函数名)作变量名。
Dim temp
Dim Str As String
Dim Date_Str As String
Dim LOG_Str As String
Date_Str = Format(Now(), "yyyy-mm-dd")
Str = Format(Now(), "yyyy-mm-dd hh:mm:ss ") & Trim(msg)
FileNum = FreeFile
FileName = Trim(App.Path & "\" & Date_Str & ".txt")
If Dir(FileName) = "" Then
'------Create File--------------------
Call Create_LOG_File
End If Open FileName For Append As #1 ' 打开文件。
Do While Not EOF(1) ' 循环至文件尾。
Line Input #1, temp ' 读入一行数据并将其赋予某变量。
LOG_Str = LOG_Str + temp + vbCrLf
Loop
Close #1 ' 关闭文件。
Open FileName For Output As FileNum
Print #FileNum, LOG_Str + Str Close #FileNumEnd Sub
直接写Open FileName For Append As #1
写多大都可以,只要你的硬盘放得下