如何用vb实现文本框内容以日期备份?

来源:百度知道 编辑:UC知道 时间:2024/05/29 21:28:10
有一个文本框text1和一个command1按钮。点击command1后,以当前日期和时间为文件名(文件名如:20081227193338)备份text1的内容。

'点击Command1后以时间为文件名保存Text1的内容到程序目录
'如果需要更改存放位置,把 App.Path & "\" 改为相应目录就可以了

Private Sub Command1_Click()
Open App.Path & "\" & Format(Now, "yyyymmddhhmmss") & ".txt" For Append As #1
Print #1, Text1.Text
Close #1
End Sub

Private Sub Command1_Click()
Dim s As String
'下一行的文件名输出格式如 2008-12-27 22:31:11
' = Replace(Now, ":", "-", , -1)
'如果按你的要求的格式,可改成如下
s = Replace(Replace(Replace(Now, ":", "-", , -1), "-", "", , -1), " ", "", , -1)
'Print s
Open App.Path & "\" & s & ".txt" For Output As #1
Print #1, Text1.Text
Close #1
End Sub

你可以先定义个变量来取得当有的日期,然后再将这个变量的值做文件名。不会哈,只是点想法!