Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
File in use
Message
From
17/10/2001 12:02:07
 
 
To
17/10/2001 11:41:39
General information
Forum:
Visual Basic
Category:
Other
Title:
Miscellaneous
Thread ID:
00569634
Message ID:
00569679
Views:
31
>I know that it's possible to trap error, but I don't want to copy and then have an error. I want to check before having an error...
>
>Patrice Merineau

There is probably some API call you can use for this (I don't know) but for the purposes of checking exclusive access handling a specific error should have the same effect as checking for its availability. This sample is from MSDN:
Function IsFileOpen(filename As String)
       Dim filenum As Integer, errnum As Integer

       On Error Resume Next   ' Turn error checking off.
       filenum = FreeFile()   ' Get a free file number.
       ' Attempt to open the file and lock it.
       Open filename For Input Lock Read As #filenum
       Close filenum          ' Close the file.
       errnum = Err           ' Save the error number that occurred.
       On Error GoTo 0        ' Turn error checking back on.

       ' Check to see which error occurred.
       Select Case errnum

           ' No error occurred.
           ' File is NOT already open by another user.
           Case 0
               IsFileOpen = False

           ' Error number for "Permission Denied."
           ' File is already opened by another user.
           Case 70
               IsFileOpen = True

           ' Another error occurred.
           Case Else
               Error errnum
       End Select
   End Function
HTH
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform