|
我这里有一段关于input函数的代码,用Freefile生成没有使用的文件号,总共有4个,t1,t2,t3,t4。但是我验证是发现t1=t2=t3=1, t4=2,这是为什么, 不是要生成未使用的文件号吗?怎么会有重复的?
Sub test()
If Dir("C:\temptemp", vbDirectory) = "" Then
MkDir ("C:\temptemp")
Dim t2 As Long
t2 = FreeFile
Open "C:\temptemp\transfer.txt" For Append As #t2
Print #t2, "hello"
Close #t2
Dim t1 As Long
t1 = FreeFile
Open "C:\temptemp\temp.txt" For Append As #t1
Print #t1, "<collection type=material >"
Print #t1, " <group >"
Close #t1
Dim temp As String
Dim t3 As Long
t3 = FreeFile
Open "c:\temptemp\transfer.txt" For Input As #t3
Dim t4 As Long
t4 = FreeFile
Open "c:\temptemp\temp.txt" For Append As #t4
MsgBox t1
MsgBox t2
MsgBox t3
MsgBox t4
Close #t3
Close #t4
End If
End Sub
问题在于你生成文件后就关闭了,所以FreeFile又从1开始,而t3生成文件后未关闭,接下来FreeFile就等于2,若再创建则会等于3........
|
|