Author |
|
patrickm Senior Member
Joined: February 22 2007 Location: United States
Online Status: Offline Posts: 188
|
Posted: June 23 2009 at 13:49 | IP Logged
|
|
|
Hello,
I am rewriting some macros and would like to be able to reference global variables within ph_forloopwinc such as ZONE_1_DURATION, ZONE_2_DURATION etc.
I cannot figure out the right syntax to create {ZONE_1_DURATION} with "ZONE",the local variable, and "DURATION" that will return the value of the variable for use in a formula.
|
Back to Top |
|
|
grif091 Super User
Joined: March 26 2008 Location: United States
Online Status: Offline Posts: 1357
|
Posted: June 23 2009 at 14:39 | IP Logged
|
|
|
Not sure if this is what you are looking for. The ph_getvar_s(1,1) gets the current content of LOCAL1 variable. The first ph_setglobal_s sets global variable GVLOCALVALUE to the string DATA. The second ph_setglobal_s sets global variable GVLOCALVALUE to the current content of LOCAL1. The ph_getglobal_s retrieves the current value of GVLOCALVALUE.
ph_getvar_s(1,1)
ph_setglobal_s("GVLOCALVALUE", "DATA")
ph_setglobal_s("GVLOCALVALUE", ph_getvar_s(1,1))
ph_getglobal_s("GVLOCALVALUE")
Perhaps if you posted an example of what you are trying (even if the syntax is wrong) someone can work out the correct syntax.
__________________ Lee G
|
Back to Top |
|
|
patrickm Senior Member
Joined: February 22 2007 Location: United States
Online Status: Offline Posts: 188
|
Posted: June 23 2009 at 17:12 | IP Logged
|
|
|
Thanks for your response. What I am trying to do is reference a number of global variables in a loop. In C i would have simply used an array to access each variable in the loop. So what I'm trying to do is run a formula n times with argument variable[n]
|
Back to Top |
|
|
TonyNo Moderator Group
Joined: December 05 2001 Location: United States
Online Status: Offline Posts: 2889
|
Posted: June 23 2009 at 19:23 | IP Logged
|
|
|
I think this would work, assuming LOCAL1 is your loop counter...
ph_getglobal_n( "ZONE_" + ph_getvar_s( 1, 1) + "_DURATION")
|
Back to Top |
|
|
dhoward Admin Group
Joined: June 29 2001 Location: United States
Online Status: Offline Posts: 4447
|
Posted: June 29 2009 at 12:48 | IP Logged
|
|
|
Patrick,
Tony has you covered. You would definately want to use the ph_getglobal_n form of referencing the global variable since the {ZONE_1_DURATION} form is ONLY substituted (think search and replace) BEFORE the formula is evaluated. So "{ZONE_" + "[LOCAL1]" + "_DURATION" would never be substituted (the string concatenation is performed DURING evaluation (after variable substitution is already performed).
HTH,
Dave.
|
Back to Top |
|
|