* ve_excl Library determining whether we
* have exclusive use of the data or not by Adam Weisberg
* Note global variables: g_cDataPath is the dir of you data
* which needs to end in a backslash
* Public g_nSysHandle should be set to 0 or -1 before you run this
* in your main calling program.
*******************
Function EnterShare
*******************
* This should be run on entry to the system
**********************************************************
* It returns:
* 1 if we can enter the system (multiuser)
* 2 if we cannot enter the system as it is being used excl
* 3 if we got an error.
**********************************************************
Local l_nHandle
* Close the system file if it is open.
IF TYPE('g_nSysHandle') = 'N' AND g_nSysHandle > 0
=FCLOSE(g_nSysHandle) && Close the system file
ENDIF
IF !File(g_cDataPath + 'MC001.SYS')
l_nHandle=FCreate(g_cDataPath + 'MC001.SYS')
=FPuts(l_nHandle,Chr(26) + 'ANW 1998')
=FCLOSE(l_nHandle)
ENDIF
IF !File(g_cDataPath + 'MC001.SYS')
=MessageBox('Error creating system file.'+Chr(13)+;
'Make sure you have Write access to the data directory.' + Chr(13) +;
'(This has to do with your network setup.)',16,'Cannot Enter System')
RETURN 3
ENDIF
g_nSysHandle = FOPEN(g_cDataPath + 'MC001.SYS')
IF g_nSysHandle < 0
RETURN 2
ELSE
RETURN 1
ENDIF
ENDPROC
******************
Function EnterExcl
******************
* Returns
* 1 If I can get exclusive use
* 2 If I can't
* 3 If there is an error that means I need to be booted
Local l_nHandle
* Close the system file if it is open.
IF TYPE('g_nSysHandle') = 'N' AND g_nSysHandle > 0
=FCLOSE(g_nSysHandle) && Close the system file
ENDIF
* Create the system file if it does not exist.
IF !File(g_cDataPath + 'MC001.SYS')
l_nHandle=FCreate(g_cDataPath + 'MC001.SYS')
=FPuts(l_nHandle,Chr(26) + 'ANW 1998')
=FCLOSE(l_nHandle)
ENDIF
IF !File(g_cDataPath + 'MC001.SYS')
=MessageBox('Error creating system file.'+Chr(13)+;
'Make sure you have Write access to the data directory.' + Chr(13) +;
'(This has to do with your network setup.)',16,'Cannot Enter System')
RETURN 3
ENDIF
g_nSysHandle = FOPEN(g_cDataPath + 'MC001.SYS',12) && Read/Write/Unbuffered
IF g_nSysHandle < 0 && Failure - try to reopen SHARED
g_nSysHandle = FOPEN(g_cDataPath + 'MC001.SYS',0)
IF g_nSysHandle < 0
RETURN 3
ELSE
RETURN 2
ENDIF
ELSE
RETURN 1
ENDIF
ENDPROC
***************
Function OnExit
***************
=FCLOSE(g_nSysHandle)
ENDPROC