在VB中,怎样在创建文件名时加入系统时间

如题所述

第1个回答  2011-10-31
Private Sub Command1_Click()
Set fs = CreateObject("Scripting.FileSystemObject")
Set a = fs.CreateTextFile("c:\" & Format(Date, "yyyy.mm.dd") & " " & Format(Time, "hh.mm.ss") & ".txt", True)
a.WriteLine ("This is a test.")
a.WriteLine ("这是一个测试用例。")
a.Close
Shell "notepad.exe " & "c:\" & Format(Date, "yyyy.mm.dd") & " " & Format(Time, "hh.mm.ss") & ".txt", vbNormalFocus
End Sub本回答被提问者采纳
第2个回答  2011-10-31
先调用Time函数,得到当前时间。再用Str函数,把时间转成字符串,然后把这个字符串作为文件名就行了。
第3个回答  推荐于2017-10-08
Visual Basic code

Conn.Execute "select 日期 as 日期, 时间 as 时间, 浓度 as 浓度 into [Excel 8.0;database=" & App.Path & "\Data" & Format$(Now, "yyyy-mm-dd HHNNSS") & ".xls].sheet1 from nongdubiao"本回答被网友采纳
第4个回答  2011-11-01
Dim 文件名 As String
文件名 = Format(Now, "YYYY-MM-DD_HHNNSS") & ".txt"
MsgBox 文件名
相似回答