Active TopicsActive Topics  Display List of Forum MembersMemberlist  Search The ForumSearch  HelpHelp
  RegisterRegister  LoginLogin
PowerHome General
 PowerHome Messageboard : PowerHome General
Subject Topic: referencing global variables Post ReplyPost New Topic
Author
Message << Prev Topic | Next Topic >>
patrickm
Senior Member
Senior Member


Joined: February 22 2007
Location: United States
Online Status: Offline
Posts: 188
Posted: June 23 2009 at 13:49 | IP Logged Quote patrickm

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 View patrickm's Profile Search for other posts by patrickm
 
grif091
Super User
Super User


Joined: March 26 2008
Location: United States
Online Status: Offline
Posts: 1357
Posted: June 23 2009 at 14:39 | IP Logged Quote grif091

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 View grif091's Profile Search for other posts by grif091
 
patrickm
Senior Member
Senior Member


Joined: February 22 2007
Location: United States
Online Status: Offline
Posts: 188
Posted: June 23 2009 at 17:12 | IP Logged Quote patrickm

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 View patrickm's Profile Search for other posts by patrickm
 
TonyNo
Moderator Group
Moderator Group
Avatar

Joined: December 05 2001
Location: United States
Online Status: Offline
Posts: 2889
Posted: June 23 2009 at 19:23 | IP Logged Quote TonyNo

I think this would work, assuming LOCAL1 is your loop counter...

ph_getglobal_n( "ZONE_" + ph_getvar_s( 1, 1) + "_DURATION")
Back to Top View TonyNo's Profile Search for other posts by TonyNo Visit TonyNo's Homepage
 
dhoward
Admin Group
Admin Group
Avatar

Joined: June 29 2001
Location: United States
Online Status: Offline
Posts: 4447
Posted: June 29 2009 at 12:48 | IP Logged Quote dhoward

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 View dhoward's Profile Search for other posts by dhoward Visit dhoward's Homepage
 

If you wish to post a reply to this topic you must first login
If you are not already registered you must first register

  Post ReplyPost New Topic
Printable version Printable version

Forum Jump
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot delete your posts in this forum
You cannot edit your posts in this forum
You cannot create polls in this forum
You cannot vote in polls in this forum