tags:

views:

285

answers:

3

If I attempt to gain an exclusive table open in FoxPro, it generates a dialog box if access is denied. Since I'm targeting an non-interactive application, is there a way to detect whether the operation will succeed, or at least have it fail silently?

A: 

If you have VFP 8 or greater:

TRY
    USE MyTable IN 0 EXCLUSIVE
ENDTRY
...
IF USED ("MyTable")
    *-- Use the table here
ENDIF

izokurew
Just found that. However, I found that I needed an (empty) CATCH statement.
Justin Love
A: 

For older versions:

cOldError = ON("ERROR")
ON ERROR *
USE MyTable IN 0 EXCLUSIVE
lSuccess = used("MyTable")
ON ERROR &cOldError

if lSuccess ...
Stuart Dunkeld
A: 

I've had success using FOPEN...

nFHdl = FOPEN("myfile.dbf", 1)  &&  1 tries to open the file for writing
IF nFHdl > 0 THEN
   FCLOSE(nFHdl)
   USE myfile.dbf exclusive
ELSE
   = messagebox("Can't open Exclusive")
ENDIF
ChrisS