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

Macro Substitution to db aliases

Status
Not open for further replies.

redshadow

Programmer
May 24, 2001
70
PH
Hi there,
I have a problem using the macro substitution (&) in VFP.
What I've done is I read a directory with text files and convert them to dbf format and add the name of the converted dbfs in a list box. The problem was the listbox now cannot be clicked, what I mean is that I can't choose a specific item from a listbox.

Another thing is that when i loop through the listbox and issuing:
use &DBName

the dbname is the variable i used to assign base on the value from the listbox.
It goes smoothely but the problem was when I try to issue twice the command

select &dbname

what foxpro did is it changes the alias name so I can now receive an error.

by the way the value in the listbox does not contain the extension name of the dbf, it only holds the basename.

Thanks in advance, hope you'll be of help.
 
Instead of macrosubstitution
try rather name expression, e.g.
use (DBName)
 
Thanks for the help anyway but I already had tried using that, but the error still occurs. I wonder if it is on the environment, because I am issuing the use only once.

The problem actually occured when I ran the code the second time, that is I am wondering if it is on the environment from which I ran the program. And this should not happen.

The exact code is:
for nCnt = 1 to thisform.pageframe1.page2.list1.listcount
dbName = thisform.pageframe1.page2.list1.list(nCnt)
select &dbname && or select (dbname)
&& other code... it is long
&&again I will issue select to close it
select (dbname)
use && the secon dtime I ran this It issues an error
&& that it cannot find the alias name

next nCnt

 
Hi!

Corrected code:

with thisform.pageframe1.page2.list1
for nCnt = 1 to .listcount
use (alltrim(.list(nCnt))) in 0 again alias TMP_TMP
&& do not forget alltring for list values. When there
&& are spaces in it, () instead & will not work
&& use free workarea, otherwise you risk to close bu
&& USE command the current alias

select TMP_TMP && fixed alias name is much more
&& comfortable

&& other code... it is long - working over the TMP_TMP alias

&& close it
use in TMP_TMP
next nCnt
endwith

Above code is far more readable and reliable.

Hope this helps.

Vlad Grynchyshyn
vgryn@softserve.lviv.ua
The professional level of programmer could be determined by level of stupidity of his/her bugs
 
The error is not because of your macro substitution. The error is because SELECT cannot find the alias.

In youe code ...
for nCnt = 1 to thisform.pageframe1.page2.list1.listcount
****** 'dbname' shall not contain spaces and
****** so I suggect issue ALLT(dbname) to a variable and
****** then use it in the macro or ()
dbName = ALLT(thisform.pageframe1.page2.list1.list(nCnt))
****** here you are selecting the alias already open....
select &dbname && or select (dbname)
&& other code... it is long
&& again I will issue select to close it
*********************************************************
****** I dont understand why you select the same again ..
****** though this will not return any error, if the
****** alais name is correct .. once you are here..
select (dbname)
********************************************************
****** here the selected file is closed.
use && the second time I ran this It issues an error
&& that it cannot find the alias name
next nCnt
======================================================
I believe your intension is to close the DBFs..
Once you select and close the DBF.. the line from be deleted from the list. Failure will lead to the 'alias' being not available.
You can check for the availability of the alias... using the funcion...
IF USED('myAlias')
SELECT (myAlias)
USE
ENDIF

So in effect your code can be replaced like this
========================================================
for nCnt = 1 to thisform.pageframe1.page2.list1.listcount
dbName = ALLT(thisform.pageframe1.page2.list1.list(nCnt))
IF USED(dbname)
SELECT (dbname)
** If your intention is to open the dbf then
** USE (dbname) IN 0
**
** Put Code to do whatever you want before closing
USE
ENDIF
next nCnt
======================================================
Hope this helps... ramani :-9
(Subramanian.G)
FoxAcc
ramani_g@yahoo.com
 
Many thanks to all of you. I now figured out what's wrong with my code.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top