CodeItBetter Programming Another VB Programming Blog

How to Open a File and return the File Number

Posted on January 5, 2009
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
'File/Folder Handling - How to Open a File and return the File Number
Option Explicit
 
Public Function OpenFile(ByVal FilePath As String) As Long
    On Error GoTo OpenFile_Error
 
    If Len(Dir$(FilePath)) = 0 Then
        OpenFile = -1
        Exit Function
    End If
 
    OpenFile = FreeFile
    Open FilePath For Input As #OpenFile
 
ExitHere:
    On Error GoTo 0
    Exit Function
 
OpenFile_Error:
    OpenFile = -2
    MsgBox "Error " & Err.Number & " (" & Err.Description & ") in procedure OpenFile of Form Form1"
End Function
Comments (0) Trackbacks (0)

No comments yet.


Leave a comment


 

No trackbacks yet.