INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

Trying to close tables listed in an array

Trying to close tables listed in an array

(OP)
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)

RE: Trying to close tables listed in an array

2
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 SELECT (mytable) and SELECT &mytable 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.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close