Subject Re: REFERRING TO A VARIABEL TO REP A VALUE
From Ken Mayer <dbase@nospam.goldenstag.net>
Date Mon, 13 Nov 2023 21:28:34 -0800
Newsgroups dbase.getting-started

On 11/13/2023 3:05 PM, ED FURCHE wrote:
> ED FURCHE Wrote:
>
>> Ken Mayer Wrote:
>>
>>> On 11/12/2023 9:17 AM, ED FURCHE wrote:
>>>> I HAVE USED THIS BEFORE BUT DONT REMEMBER HOW.
>>>>
>>>> I WANT TO REFER TO A VARIABLE IN A COMMAND
>>>>
>>>> EXAMPLE  CTR=1
>>>> USE C:\BACKUP\CTR\CHECK.DBF TO ADDRESS USE C:\BACKUP\1\CHECK
>>
>> I TRIED THIS  DIDNT WORK.   CTR=1
>> USE C:\BACKUP\&CTR\CASEY.DBF ALIAS OLDFILE
>>>>
>>>
>>> You would do this in a couple ways, the easiest is to build the command
>>> as a string, and insert the variable into it:
>>>
>>> cCmd = [USE C:\BACKUP\]+CTR+[CTR\CHECK.DBF TO ADDRESS USE C:\BACKUP\1\CHECK]
>>>
>>> Note that by using the square brackets as delimiters you don't have any
>>> confusion with quotes ...
>>>
>>> To execute the command (use macro expansion):
>>>
>>> &cCmd.
>>>
>>> Another way is:
>>>
>>> USE C:\BACKUP\&CTR.\CHECK.DBF TO ADDRESS USE C:\BACKUP\1\CHECK
>>>
>>> But that gets a bit hard to read, and it's easy to make mistakes. Also
>>> if the value of your variable includes spaces, it can be a problem,
>>> you'd have to deal delimiters ...
>>>
>>> Ken
>>>
>>>
>>> --
>>> *Ken Mayer*
>>> Ken's dBASE Page: http://www.goldenstag.net/dbase
>>> The dUFLP: http://www.goldenstag.net/dbase/index.htm#duflp
>>> dBASE Books: http://www.goldenstag.net/dbase/Books/dBASEBooks.htm
>>> dBASE Tutorial: http://www.goldenstag.net/dbase/Tutorial/00_Preface.htm
>>> dBASE Web Tutorial: http://www.goldenstag.net/dbase/WebTutorial/00_Menu.htm
>>> dBASE DOS to Windows Tutorial:
>>> http://www.goldenstag.net/dbase/DtoWTutorial/00_Menu.htm
>>>
>> I TRIED THIS...
>
> CTR=1
> USE C:\BACKUP\+&CTR.\CHECK.DBF
> THEN THIS...
>
>
> CTR=1
> USE C:\BACKUP\+&CTR\CHECK.DBF  WIDTHOUT THE PERIOD  (I FELT THAT YOUR PERIOD WAS A MISTAKE)

Leave out the PLUS SIGN, and put the period back in, it wasn't a mistake.

The period is the terminator character for macro expansion, it starts
with the ampersand and ends with the period.

USE C:\BACKUP\&CTR.\CHECK.DBF

Try that. But as Mervyn points out, you should really use the option to
build a whole string as a command (put it in a variable) and then
execute the variable as a macro -- two separate commands shown below:

cCmd = [USE C:\BACKUP\]+CTR+[CTR\CHECK.DBF TO ADDRESS USE C:\BACKUP\1\CHECK]
&cCmd.

Ken


--
*Ken Mayer*
Ken's dBASE Page: http://www.goldenstag.net/dbase
The dUFLP: http://www.goldenstag.net/dbase/index.htm#duflp
dBASE Books: http://www.goldenstag.net/dbase/Books/dBASEBooks.htm
dBASE Tutorial: http://www.goldenstag.net/dbase/Tutorial/00_Preface.htm
dBASE Web Tutorial: http://www.goldenstag.net/dbase/WebTutorial/00_Menu.htm
dBASE DOS to Windows Tutorial:
http://www.goldenstag.net/dbase/DtoWTutorial/00_Menu.htm