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

When & WhenNot to use &var and (var)

Status
Not open for further replies.

stanlyn

Programmer
Sep 3, 2003
945
US
Hi,

Can someone explain the proper usage of macto expansion such as &var and evaluation such as (var)?

I've been using them for years without really knowing exactly when they should be used and/or avoided. When I use them and I have an error, I simple switched to the other version, and all without really knowing the pros, cons, and gotchas. Typically I use:

1. lcVariable
2. &lcVariable
3. (lcVariable)

And yes, I've read the help docs, but asking here more about real life experiences with them. Like a rule of thumb...

Thanks,
Stanley
 
In addition to the resources that Scott mentioned, there are two particular collections of articles that you are sure to find helpful. The first are by Tamar on her Tomorrow Solutions website. The others are by Doug Hennig - those on his personal site.

I don't know off-hand if there are any articles on either of those sites that will answer your specific question about macros. But they are definitely worth reading for background information and general self-education.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
This is a similar decision whether to use TYPE() or VARTYPE(). The reference says to use VARTYPE as much as possible, it is faster. I consider TYPE() to be more versatile than VARTYPE(). TYPE() allows you to drill down an extra level, but the penalty is that it is a little slower so if possible you want to use VARTYPE inside code that loops a lot.

thread184-1155923
VARTYPE({varName})

TYPE("{varName or data}")... returns data type of variable or data

TYPE({varName}) ... returns data type of variable named inside varName

Example:
VarNum=1
VarChr="VarNum"
? TYPE("VarChr")
C
? TYPE(VarChr)
N

thread184-1346221
 
Thanks Tamar, I just finished reading your article and will be applying those rules. It was an easy read and easy to understand. I already know of some places in code that I can speed up with the macro, instead of wasting time evaluation every record.

Also, dbMark, I've never heard of vartype(), so learned something new that I'll be working with...

Thanks again,
Stanley
 
>This was just a very simple example. My point is that evaluate(lcX) behaves just like &lcX or ExecScript(lcX), in other words, you can use Evaluate() to run code
Yes, that's known, And so?

I still wonder what made you react and what you think I have wrong.

Bye, Olaf.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top