VB 用vb打开txt文件后保存,如何解决自动命名的问题?

来源:百度知道 编辑:UC知道 时间:2024/06/21 11:02:57

Dim a As Long, b As String
a = 1
1
b = "d:\" & a & ".txt"
If Dir(b) = "" Then
Open b For Append As #1
Write #1, Text1.Text
Close #1
Else
a = a + 1
GoTo 1
End If

Open App.path & "\xx" & Time & ".txt" for Output as #1
Print #1,(你的内容)
Close #1
要解决自动保存而不覆盖的话,可以考虑time函数作文件名.
如果愿意覆盖那就简单了,你的文件叫xx.txt那么
Open App.path & "\xx.txt" for Output as #1
Print #1,(你的内容)
Close #1

随机吧 弱弱的说一句 chr(int(rnd*58+65)) & int(rnd*100) & ".txt" 看来在加强一下 随机一个字母再加随机数字
不过我的意见是自动命名最好是连续的好一些杂乱无章难以管理

Open App.path & "aa" & t for Output as #1
Print #1,(你的内容)
t=t+1
Close #

取随机数量级理论上也有重复的可以.
唯一的不重的方法是
用当前备份时的时间年月日时份秒毫秒作为文件名

加一通用对话框控件,