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

cTableAlias does not work when a variable containing the table name is passed to SELECT cTableAlias

Status
Not open for further replies.

Arthur Lewis

Programmer
Jul 10, 2021
9
LC
cTableAlias does not work when a variable containing the table name is passed to SELECT cTableAlias or USED(cTableAlias)

This a very strange case. Table test.dbf is clearly open in the current datasession. If I run from the IDE
? USED('test.dbf') it returns .T.

However I when I do the following it fails.
PROCEDURE myUSED()
LOCAL lcTable as string
STORE 'test.dbf' TO lcTable
IF USED(lcTable)
RETURN .T.
ENDIF
** IT returns .F. when test.dbf is open in the current datasession.

Also when I do

SELECT (lcTable) is says alias does not exist...

HERE the actual code. Where the SELECT statement failed.

SELECT_Error_xr0c4z.png
 
USED() only checks ALIAS names. See its help topic.

After you USE test.dbf a USED('test') will return .T.
So if you're after a function determining whether aq certain DBF file is open, you have to cycle through AUSED() and look into DBF() of every element.

It's quite normal to name tables so that their default alias is their file name (without the DBF extension).

Your case of LK_PARISH is strange at first glimpse but you have a trailing space in thisform.aFamily(2).

Chriss
 
Chris Miller

Sir, thanks a million. I spent so much time on this and can't believe that I did not see that space. That was the problem. I am so ashamed of myself.
Do I have your permission to delete this post. I don't think it will serve anyone any good. What do you think?
 
You're free to use the features of the site.
Anything can hold as an example, but no need to keep this thread, I agree.

Chriss
 
Arthur,

As well as the issue with the trailing space, Chris made another important point. In your test code, you set lcTable to Test.DBF, and then tested for that using USED(). But USED() takes an alias, not a table name, and by default the alias does not include the .DBF extension. If you had set lcTable to just Test, it would have worked as expected.

Please don't delete your post. If you did, we would lose the entire thread, and the thread might well be of interest to others.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
Mike, I can understand his embarrassement, though everyone knows such off by one or similar mistakes. Last time I had a problem in a PHP script due to a backtick at the wrong place. It lead to error report of a missing curly bracket where pointing out a spurious backtick would have helped me much more.

Anyway, I think there is no need to keep this thread.

Chriss

PS: I think when you delete your first post that will delete the whole thread.
Deleting and editing have a timeout period, though.
 
myearwood

Okay, I could have been more efficient with the code as you did. Thanks. I will replace my codes with it.

Thanks to all who assisted.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top