Would it be easy to convert the following function so that instead of just 0 or 1 it gave the following three outputs:
0 – means file closed
1 – means file is already open
2 – means file does not exist
Here’s the Function
Function IsFileReadOnlyOpen(FileName As String)
Dim iFilenum As Long
Dim iErr As Long
On Error Resume Next
iFilenum = FreeFile()
Open FileName For Input Lock Read As #iFilenum
Close iFilenum
iErr = Err
On Error GoTo 0
Select Case iErr
Case 0: IsFileReadOnlyOpen = 0
Case 70: IsFileReadOnlyOpen = 1
Case Else: Error iErr
End Select
End Function
You could add this at the beginning of your function:
I agree with the comment that you should use enum to make it easier to understand.
PS: As commented by Martin Milan this might cause issues. Alternatively, you can use this: