Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Code for PACKING table won't get file handle
Message
General information
Forum:
Visual FoxPro
Category:
Databases,Tables, Views, Indexing and SQL syntax
Title:
Code for PACKING table won't get file handle
Environment versions
Visual FoxPro:
VFP 9 SP2
OS:
Vista
Database:
Visual FoxPro
Miscellaneous
Thread ID:
01473491
Message ID:
01473491
Views:
109
I've been trying to get my code to work, but something must be wrong. It never gets a file handle. It always comes up as -1.

Cecil
* Get rid of all QUOTES records, which are marked for deletion.
* Declare and Initialize variables.
#DEFINE CRLF CHR(10)+CHR(13)
#DEFINE NREADWRITE 12
LOCAL ;
	lcFileName As Character, lcMessageText1 As Character, ;
	lcTitleBarText1 As Character, lnResponse1 As Integer, ;
	lcMessageText2 As Character, lcTitleBarText2 As Character, ;
	lnResponse2 As Integer, lnFileHandle As Integer, ;
	lnDeletes As Integer, lnYes As Integer, llGo As Logical

lcFileName="C:DEV\CMW\DATA\QUOTES.DBF"
lcMessageText1="File is in use. Do you want to try again?"
lcTitleBarText1="File is in use."
lnDeletes=0
lnYes=6		&& For MessageBox response.
llGo=.T.	&& Loop Local Logical.

SET STEP ON
* Loop.
DO WHILE llGo
	* Open and Close file quickly.
	lnFileHandle=FOPEN(lcFileName, NREADWRITE)
	llFileClosed=FCLOSE(lnFileHandle)
	* If the file didn't close, use the CLOSE ALL command; it closes all low-level files.
	IF llFileClosed = .F.
		CLOSE ALL
	ENDIF
	* Find out what happened.
	IF lnFileHandle < 0		&& File could not be opened exclusively.
		lnResponse1=MESSAGEBOX(lcMessageText1, 4+32, lcTitleBarText1)
		IF lnResponse1 = 6	&& YES.
			llGo = .T.	&& Stay in Loop. Try to open file in exclusive mode again.
		ELSE
			llGo = .F.	&& Exit loop. Do not try to open file exclusively again.
		ENDIF
	ELSE
		* No one else has the file open, so open it now in Exclusive mode.
		USE (lcFileName) EXCLUSIVE IN 0
		SELECT QUOTES
		COUNT FOR DELETED() TO lnDeletes
		IF lnDeletes > 0
			IF lnDeletes = 1
				lcMessageText2= ;
					"There is 1 record marked for deletion." + ;
					CRLF + ;
					"Do you want to proceed to PACK the QUOTES table?"
			ENDIF
			IF lnDeletes > 1
				lcMessageText2= ;
					"There are " + ALLTRIM(STR(lnDeletes)) + ;
					" records marked for deletion." + ;
					CRLF + ;
					"Do you want to proceed to PACK the QUOTES table?"
			ENDIF
			lcTitleBarText2="Decision Time."
			lnResponse2=MESSAGEBOX(lcMessageText2, 4+32, lcTitleBarText2)
			IF lnResponse2=lnYes
				WAIT WINDOW NOWAIT "Removing all records marked for deletion..."
				PACK
			ENDIF
			llGo = .F.	&& Drop out of loop.
		ELSE
			lcMessageText2 ="NO records were marked for deletion."
			lcTitleBarText2="Nothing to do!"
			MESSAGEBOX(lcMessageText2, 0+64, lcTitleBarText2)
			llGo = .F.	&& Drop out of loop.
		ENDIF
		* Close QUOTES table.
		USE
		CLOSE DATABASES
	ENDIF
ENDDO
Next
Reply
Map
View

Click here to load this message in the networking platform