vb中怎样根据日期 动态生成LOG文件

来源:百度知道 编辑:UC知道 时间:2024/09/20 23:37:26
不好意思,好像 是我没说明白 。我的意思是怎样根据日期生成log文件的名字。比如说 20081104ABC.log

'很简单,添加一个过程 MyLog
'在 Form_Load 中加入 Call MyLog("启动")
'在 Form_Unload 中加入 Call MyLog("退出")

Private Sub Form_Load()
Call MyLog("启动")
End Sub

Private Sub Form_Unload(Cancel As Integer)
Call MyLog("退出")
End Sub

Private Sub MyLog(nStr As String)
Dim F As String, H As Long

nStr = Format(Now, "yyyy-mm-dd hh:mm:ss") & nStr
F = "C:\myprog.log"
'如果要将文件保存到与你的 exe 相同的文件夹,将上句改为 F = App.Path & "\myprog.log"

H = FreeFile
Open F For Append As #H
Print #H, nStr
Close #H
End Sub

'补充
Private Sub Command1_Click()
Dim F As String
F = Format(Now, "yyyymmdd") & "abc.log"
End Sub