Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

DBFs not closing after an empty 'USE' 1

Status
Not open for further replies.

WeirdScience

Programmer
Aug 22, 2006
13
NL
Hi Gurus,

We have a foxpro 8.0 application which reads a sort of Settings dbf for several public/global settings.

We heard from several users that a lot of errors related to this settings file are occuring in the system.

Now we've checked on the Windows 'Open Files' tab that this settings file is not closed correctly or immediately.

Basically this is the code for one of the functions which set these global settings.

Anyone with a suggestion?

Code:
FUNCTION l1_path
	PARAMETER lKey
	PRIVATE lArea, sFullPath
	
	sFullPath  = LEFT(SYS(16,0), RAT("\", SYS(16,0))) + "path.dbf"

	lArea = ALIAS()

* Check whether the PATH.DBF table is in the current directory
	IF NOT FILE(sFullPath)
	    R=l1_beep("error")
		WAIT WINDOW "FILE ERROR : PATH.DBF NOT FOUND IN CURRENT DIRECTORY !"
		QUIT
	ENDIF

* Open the PATH table in the next available workspace
	TRY
		USE &sFullPath ALIAS dbpath SHARED IN 0
	CATCH
		TRY
			USE &sFullPath ALIAS dbpath SHARED IN 0
		CATCH
			WAIT WINDOW "Error opening PATH.DBF [l1_path]" NOWAIT		
			USE &sFullPath ALIAS dbpath SHARED IN 0
		ENDTRY
	ENDTRY

	SELECT dbpath

* Select the value needed using the key used
	LOCATE FOR ALLTRIM(UPPER(dbpath.key)) = ALLTRIM(UPPER(lKey))
	IF NOT FOUND()
	    R=l1_beep("error")
		WAIT WINDOW "PATH ERROR : KEY '" + lKey +"' NOT FOUND !"
	
		SELECT dbpath
		USE
		QUIT
	ENDIF

* Store path in memory and close the table
	lValue = dbpath.Value
	SELECT dbpath
	USE

* Check whether the locate came up with a value at all 
	IF Empty(Alltrim(lValue))
	    R=l1_beep("error")
		WAIT WINDOW "PATH ERROR : KEY '" + lKey +"' HAS NO VALUE !"
		QUIT
	ENDIF
	
* Check whether PATH returned exists
*	IF NOT FILE(ALLTRIM(lValue) + "\nul")
*	    R=l1_beep("error")
*		WAIT WINDOW "PATH ERROR : " + UPPER(lKey) + " '" + ALLTRIM(lValue) + "' NOT FOUND !"
*		QUIT
*	ENDIF
	
	IF(!EMPTY(lArea))
		SELECT &lArea
	ENDIF
	
	lKey=ALLTRIM(lValue)
	RETURN lKey

Regards,
Weird Science
 
See some corrections I made:
Code:
FUNCTION l1_path
    PARAMETER lKey
    PRIVATE lArea, sFullPath
    
    sFullPath  = addbs(justpath(SYS(16,0))) + "path.dbf"

    lArea = select() && Save currently selected area

* Check whether the PATH.DBF table is in the current directory
    IF empty sys(2000, sFullPath) && File function has its oddities
        R=l1_beep("error")
        WAIT WINDOW "FILE ERROR : PATH.DBF NOT FOUND IN CURRENT DIRECTORY !"
        QUIT
    ENDIF

* Open the PATH table in the next available workspace
    TRY
        USE (sFullPath) ALIAS dbpath SHARED IN 0 && Don't use macro when it's not needed (if path has spaces, it would fail)
    CATCH
        TRY
            * ? why the second try ?
            USE (sFullPath) ALIAS dbpath SHARED IN 0
        CATCH
            WAIT WINDOW "Error opening PATH.DBF [l1_path]" NOWAIT        
            * Here it is placed in error 
*            USE &sFullPath ALIAS dbpath SHARED IN 0
        ENDTRY
    ENDTRY

    SELECT dbpath

* Select the value needed using the key used
    LOCATE FOR ALLTRIM(UPPER(dbpath.key)) = ALLTRIM(UPPER(lKey))
    IF NOT FOUND()
        R=l1_beep("error")
        WAIT WINDOW "PATH ERROR : KEY '" + lKey +"' NOT FOUND !"
    
        SELECT dbpath
        USE
        QUIT
    ENDIF

* Store path in memory and close the table
    lValue = dbpath.Value
*    SELECT dbpath
    USE IN dbPath && one less command

* Check whether the locate came up with a value at all 
    IF Empty(Alltrim(lValue))
        R=l1_beep("error")
        WAIT WINDOW "PATH ERROR : KEY '" + lKey +"' HAS NO VALUE !"
        QUIT
    ENDIF
    
* Check whether PATH returned exists
*    IF NOT FILE(ALLTRIM(lValue) + "\nul")
*        R=l1_beep("error")
*        WAIT WINDOW "PATH ERROR : " + UPPER(lKey) + " '" + ALLTRIM(lValue) + "' NOT FOUND !"
*        QUIT
*    ENDIF
    
    SELECT (lArea) && No need for macro here either
     
    lKey=ALLTRIM(lValue)
    RETURN lKey
---------------------------------------
One problem is that you had USE in the CATCH statement causing another unhandled error. Another is in using macro instead of name expression.

Also I don't understand why do you have try/catch block inside the try/catch. Are you attempting two tries of openning the table?
 
Hi markros,

First of all I want to thank you for the quick response.

I'll hack your changes into our program and mondaymorning first thing I'll set the programm live for the firm.

So we'll know by monday/tuesday any response.

Any other suggestions are still welcome offcourse!

I reward it at least with star!!

WeirdWcience

--------------------------
Foxpro.. Why-oh-why?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top