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 wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Are you bored with closing tables? 1

Status
Not open for further replies.

bon011

Programmer
Jun 2, 2002
155
CZ
Hi all,

When I need to close some table or cursor so I used to type this code for many times:

If used("aTable")
select "aTable"
use
endif

Now I wrote to myself this smole function that make it for me.

function close_tab(cAlias)
if used(cAlias)
select(cAlias)
use
return 1 &&Table is close
else
return 0 &&Table wasnt open
endif
endfunc

I can now type only this :
close_tab("aTable")

Now I dont have to care about some aliases.
You can used it too. It is very handfull.
 
Nice function, Bon.

Here is another way of achieving the same thing:

USE IN SELECT("MyTable")

If MyTable is open, SELECT() returns its work area, and so the USE will close it. If MyTable is not open, SELECT() returns 0, soe the USE does nothing.

Mike


Mike Lewis
Edinburgh, Scotland
 
Another way to acheve the same goal (gotta pass the alias name, though, or use SELECT([cAlias]) as parameter):
Code:
*************************************************************************************************************************
FUNCTION EnsureClosed(tcAlias)
*************************************************************************************************************************
** Function Name : Ensure Closed
** Purpose       : Ensure that a table file with the given alias name is closed.
** Description   : Checks if alias exists. If yes - tries to close it up to 100 times.
** Parameter(s)  : Table alias name.
** Return        : Success as Boolean.
** Side Effect(s): May slow down performance when run through a slow network system.
** Notes         : None.
*************************************************************************************************************************
LOCAL I
tcAlias = UPPER(ALLTRIM(tcAlias))
IF EMPTY(tcAlias)
   RETURN .T.
ENDIF
IF !USED(tcAlias)
   RETURN .T.
ENDIF
I = 0
DO WHILE USED(tcAlias)
   USE IN (tcAlias)
   I = I + 1
   IF I = 100 && Arbitrarely!
      EXIT  && DO...WHILE loop
   ENDIF
ENDDO
RETURN !USED(tcAlias)
ENDPROC
*************************************************************************************************************************
I could've used FOR I = 1 TO 100 and IF !USED()/EXIT/ENDIF construction, but I do not remember why I did it the way I did. The result would be identical anyway.


Regards,

Ilya
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top