Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Macro substitution
Message
From
15/04/1998 14:58:20
Raul Davila
Davila Programming Services
Toa Alta, Puerto Rico
 
 
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Miscellaneous
Thread ID:
00090513
Message ID:
00092227
Views:
20
>>>Hi Raul,
>>>
>>>To expand on Carlo's answer: &control..name
>>>
>>>The reason you need 2 periods: VFP has to know where to stop macro exapansion. So, the first period stops the exapansion and the second separates the object from the member.
>>
>> Hi John:
>>
>> Actually the issue was not with objects but with variables.
>> var_value = 5
>> v1 = 'var_'
>> v2 = 'value'
>> output = &v1.&v2
>>
>> Doing some speed tests the following is the best sollution (almost half the time to complete):
>> var_value = 5
>> v1 = 'var_'
>> v2 = 'value'
>> output = EVAL(v1 + v2)
>>
>> Of course those are generic examples and is not the way I'm appliying it.
>> Since the speed of EVAL() is about twice the speed of using &, is there a way
>> of doing the following using EVAL()?
>>
>> var_value = 5
>> var_name = 'var_value'
>> &var_name = 6 && var_value is now 6
>>
>> I don't see a way of using EVAL() to accomplish that, but I might be missing something.
>>
>>TIA
>
>try:
>
>var_name = 'var_value'
>store 6 to (var_name)
>
>var_value is now 6, and name resolution is tons faster than macro expansion.

That gave me an idea and I got what I was looking for.

A simple example to show what I was after:
MyTable has ten fields named F1 thru F10
for i = 1 to 10
field_name = 'F' + allt(str(i))
repl &field_name with My_Function_Returning_Something()
endfor

In that third line I want to eliminate the use of &field_name
It just didn't ocurr to me to use the (...):
for i = 1 to 10
repl (eval('F' + ltrim(str(i)))) with My_Function_Returning_Something()
endfor

It's at least twice as fast.

Thanks everyone for your help!
R. Davila
DBA / Network Administrator
Administracion de Fomento Comercial
Gobierno de Puerto Rico

Still waiting for FoxPro for LINUX
Previous
Reply
Map
View

Click here to load this message in the networking platform