The following code fragment demonstrates how the FreeFile function searches for a free file number when opening a file:
Dim i As Integer i = FreeFile Open <file> For Input As #i Do Until EOF(i) <stuff> Loop Close #i
Use this technique when there is uncertainty about about the file numbers in use.