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

Trying to close tables listed in an array 2

Status
Not open for further replies.

Bryan - Gendev

Programmer
Jan 9, 2011
408
AU
I have tried CLOSE databases but this kills tables I have set up on the fly.
I have tried....
Code:
Adir(gatable, '*.dbf')
For i = 1 To Len(gatable)
	mytable = JUSTSTEM(gatable(1,i))
	SELECT mytable
	Use
Endfor
I've tried (mytable) and &mytable but get errors.
Can someone correct my code please.
Regards
GenDev
(Bryan)
 
Gendev, you forget that SELECT mytable is not interpreting mytable as a variable name, but as literal name. That's the price we pay for wanting SELECT to work with names without quotes. When a variable of that name exists, that doesn't change this interpretation.

You surely have been told about name expressions multiple times already, so this would help:
Code:
SELECT (mytable)

And there is the alternative of macro substitution:
Code:
SELECT &mytable

There is another problem, if you don't have all tables of the directory currently opened, even [tt]SELECT (mytable)[/tt] and [tt]SELECT &mytable[/tt] will fail on that. You can make use of the similarly written SELECT(mytable) function, just without space it'll mean the SELECT() function instead of the SELECT command. It is parameterized by an alias name. The SELECT() function is returning a workarea number from an alias name. And that can be used with USE IN workarea as in:
Code:
USE IN SELECT(mytable)

The cute part of this is, whenever mytable is from a filename of your previous ADIR call, which isn't currently opened, it'll mean SELECT("something") with something not being an active alias name. And that won't error but return workarea number 0. Then finally USE IN 0 does nothing, especially it doesn't harm or error, it closes in the workarea 0, which by definition has nothing open in it, 0 always is the next empty workarea, which never changes, even after USE some.dbf in 0 some.dbf is not opening in 0, but whatever workarea>0 was not used beforehand, and 0 then will just mean the next empty workarea.

Besides all that, you might do CLOSE TABLES ALL to avoid CLOSE ALL also closing forms and other things.

And last not least, since DBFs can open up with other alias names, all this will only work on the prerequisite of never opening dbfs with other alias names. That includes the limitation of having no invalid file stem names with spaces or starting with a digit, which is possible for file names but not for alias names. If you really want to close all workareas of a directory, you'd need to determine DBF() of every alias currently open you get from AUSED() also in other data sessions you get from ASESSIONS() and then would need to scan their DBF full file names in your ADIR array, which you first also would need to extend, as it does not contain full pathed names. So all this would be much more complicated to close all dbf files the current VFP session has open from a specific directory.

Bye, Olaf.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top