问题又来了,我用VB成功生成了随机名字的文件,但是我如何获取生成的文件叫什么名字呢?
可能我解释的不够清楚,例如:
我在D盘根目录下生成了hjyi.txt这个文件,我该用什么代码来获取这个文件的文件全名并把它写入到另一个文件中呢?
不好意思,我补充一下问题,我列一下代码:
Function CreateFileName() As String
Dim Length As Integer
Dim FileName As String
Dim i As Integer
Dim aStr As String
Randomize
Length = Int(8 * Rnd() + 1)
For i = 1 To Length
aStr = Chr(25 * Rnd() + 97)
FileName = FileName & aStr
Next i
CreateFileName = "D:\" & FileName & ".txt"
End Function
Private Sub Command1_Click()
Open CreateFileName For Output As #1
Print #1, Form1.Label1.Caption
Close #1
Print CreateFileName
End Sub
我的另一个生成的文档内容是:
所记录的信息在()上.
我如何把那生成的随机文件名写入到()那里呢?
Function CreateFileName() As String
Dim Length As Integer
Dim FileName As String
Dim i As Integer
Dim aStr As String
Randomize
Length = Int(8 * Rnd() + 1)
For i = 1 To Length
aStr = Chr(25 * Rnd() + 97)
FileName = FileName & aStr
Next i
CreateFileName = "D:\" & FileName & ".txt"
End Function
Private Sub Command1_Click()
Dim FileName as String
FileName=CreateFileName()
Open FileName For Output As #1
Print #1, Form1.Label1.Caption
Print #1,"所记录的信息在(" & FileName & ")"
Close #1
Print FileName
End Sub