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

() vs &

Status
Not open for further replies.

fmoore0001

Programmer
Dec 3, 2002
192
US
Guys, I am getting an error in a program I maintain that I cannot quite figure out. The codes is:

#ifdef _COMIX_
xindex on (cIndexKey) tag temp for (cIndexFor) to ;
&cFileName
#else
index on &cIndexKey tag temp for &cIndexFor to ;
&cFileName
#endif

The program is bombing with a SYNTAX error where the &
is used, but not the (). In fact, looking at the code I thought & and () would work the same. What am I missing?

Frank
 
It is generally better to use the () syntax.

Code:
#ifdef _COMIX_
     xindex on (cIndexKey) tag temp for (cIndexFor) to ;
        (cFileName)
#else
     index on &cIndexKey tag temp for &cIndexFor to ;
        (cFileName)
#endif

You might well have a period in the cFileName variable, which clipper would/might interpret as the end of the macro substitution...

Let us know!
Regards

Griff
Keep [Smile]ing
 
Could I simply substitute the () for & and get the same result?

Frank
 
Pretty much, except there are some circumstances where the () syntax is not allowed.

For example:
Code:
do (cFileProcName)
is not valid
Code:
do &cFileProcName
would generally be fine!

I'm not 100% sure whether the index expression can be enclosed in the () syntax

HTH
Regards

Griff
Keep [Smile]ing
 
I got curious about this question snd wrote some small test prgs. So, FWIW:

Using Clipper 5.3b, Exospace, and NTX indices:

cDBF:="DBF"
cIDXKEY:="FIELD"
cIDXF:="TEMP"

The following code worked:
USE (cDBF)
INDEX ON &cIDXKEY TO (cIDXF)
USE (cDBF) INDEX (cIDXF)
------- or -------
USE &cDBF
INDEX ON &cIDXKEY TO &cIDXF
USE &cDBF INDEX &cIDXF

What DIDN'T work was:
INDEX ON (cIDXKEY) TO (cIDXF)
------- or -------
INDEX ON (cIDXKEY) TO &cIDXF

Using ? (cIDXKEY) printed "FIELD", not the value in it, for all records.
Using ? &cIDXKEY, the actual field value was printed for all records.

So, () and & are NOT equivalent when it comes to indexing. Using the "&" appears to be the safer choice.
 
Just getting my mind round it. () is used more as "evaluate" rather than & as "evaluate it and use it as if it was programmed that way". I know that there is probably a speed difference, but I doubt that nowadays that really makes much difference. The stuff below works and seems "right".

cDbf := 'TEST'
cDrive:= 'C:\DATA\'
use (cDrive+cDbf)
? (cDbf)->data

It's VERY rare that I feel the need for a macro in my programming. Having said that, part of my app allows users to put in calculations and IIF's on their data and that can wow them.

Ian Boys
DTE Systems Ltd
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top