Active TopicsActive Topics  Display List of Forum MembersMemberlist  Search The ForumSearch  HelpHelp
  RegisterRegister  LoginLogin
PowerHome Programming
 PowerHome Messageboard : PowerHome Programming
Subject Topic: Program Loop Post ReplyPost New Topic
Author
Message << Prev Topic | Next Topic >>
MAWilsonPE
Newbie
Newbie
Avatar

Joined: May 30 2008
Location: United States
Online Status: Offline
Posts: 18
Posted: May 20 2010 at 10:29 | IP Logged Quote MAWilsonPE

This should be easy but I am having trouble. I am trying to create a loop in a macro that executes a set number of times(3).

Set System   TEMP3   1
Set System   TEMP1   ph_regexdiff( "title=","AAAA","[TEMP1]",1,1)+"AAAA"
Set System   TEMP2   left(ph_regex diff("title=","AAAA","[TEMP1]",1,1),1)
Set Global    SITE77   "{SITE 77}"+"[TEMP2]"
Set System   TEMP3   [TEMP3]+1
Jump                         if ([TEMP3]=3,999,-4)

I get the error: Syntax Error in Formula: if(2=3,999,-4)

Shouldn't 2=3 be FALSE and return a value of -4 for the Jump function?

Edited by MAWilsonPE - May 20 2010 at 10:35
Back to Top View MAWilsonPE's Profile Search for other posts by MAWilsonPE
 
sjvonstein
Groupie
Groupie


Joined: February 05 2010
Location: United States
Online Status: Offline
Posts: 75
Posted: May 20 2010 at 10:54 | IP Logged Quote sjvonstein

Here's how I do a repeat in one of my macros. If you'd like an export format, let me know

FORMULA ph_setglobal_a("COUNTDOWN",30)

LABEL INCREMENT
WAIT 1
FORMULA ph_addtoglobal("COUNTDOWN", - 1)
Goto Label if({COUNTDOWN}=0,"END","INCREMENT")

LABEL END
MACRO ALLOFF
FORMULA ph_setglobal_a("COUNTDOWN"," ")
MACRO TV OFF

Edited by sjvonstein - May 20 2010 at 10:55
Back to Top View sjvonstein's Profile Search for other posts by sjvonstein
 
MAWilsonPE
Newbie
Newbie
Avatar

Joined: May 30 2008
Location: United States
Online Status: Offline
Posts: 18
Posted: May 20 2010 at 10:58 | IP Logged Quote MAWilsonPE

OK, I see. I can make that work.

I would still like to know why my "if" statement is wrong....
Back to Top View MAWilsonPE's Profile Search for other posts by MAWilsonPE
 
sjvonstein
Groupie
Groupie


Joined: February 05 2010
Location: United States
Online Status: Offline
Posts: 75
Posted: May 20 2010 at 11:02 | IP Logged Quote sjvonstein

It's possible the negative value is the problem. I've heard placing a space between the negative sign and value may be a fix. Try substituting the negative for a positive as a quick check.
Back to Top View sjvonstein's Profile Search for other posts by sjvonstein
 
BeachBum
Super User
Super User
Avatar

Joined: April 11 2007
Location: United States
Online Status: Offline
Posts: 1880
Posted: May 20 2010 at 11:23 | IP Logged Quote BeachBum

I don’t have PH in front of me now but I would remove the comma from 3999.

__________________
Pete - X10 Oldie
Back to Top View BeachBum's Profile Search for other posts by BeachBum
 
sjvonstein
Groupie
Groupie


Joined: February 05 2010
Location: United States
Online Status: Offline
Posts: 75
Posted: May 20 2010 at 11:24 | IP Logged Quote sjvonstein

He's not intending the number 3 thousand nine hundred ninety nine. He's trying to return an if 3, then 999, else -4
Back to Top View sjvonstein's Profile Search for other posts by sjvonstein
 
MAWilsonPE
Newbie
Newbie
Avatar

Joined: May 30 2008
Location: United States
Online Status: Offline
Posts: 18
Posted: May 20 2010 at 11:24 | IP Logged Quote MAWilsonPE

Hmmm,

I tried your suggestion and it is not incrementing. In the event log I can see that the global variable COUNTDOWN is changed from "blank" to 14, then 14 to "blank" again. It seems the FORMULA ph_addtoglobal("COUNTDOWN", - 1) is not working.
I tried changing the - 1 to -1 and even to 1 and it nevers adds it to COUNTDOWN.
Back to Top View MAWilsonPE's Profile Search for other posts by MAWilsonPE
 
sjvonstein
Groupie
Groupie


Joined: February 05 2010
Location: United States
Online Status: Offline
Posts: 75
Posted: May 20 2010 at 11:28 | IP Logged Quote sjvonstein

set all macro/formula executions to POST instead of immediate and try again.

Retain the space in - 1

Edited by sjvonstein - May 20 2010 at 11:29
Back to Top View sjvonstein's Profile Search for other posts by sjvonstein
 
MAWilsonPE
Newbie
Newbie
Avatar

Joined: May 30 2008
Location: United States
Online Status: Offline
Posts: 18
Posted: May 20 2010 at 11:37 | IP Logged Quote MAWilsonPE

OK,

Using a combination of mine and yours I got it to work. It seems the JUMP function will not accept a negative value and that is my syntax error. So I am using two LABELS and the Goto Label to get the loop working. I am using the counter I set up, TEMP3 increments and the Goto Label jumps ot of the loop when TEMP3 hits the limit.

Thanks alot!
Back to Top View MAWilsonPE's Profile Search for other posts by MAWilsonPE
 
BeachBum
Super User
Super User
Avatar

Joined: April 11 2007
Location: United States
Online Status: Offline
Posts: 1880
Posted: May 20 2010 at 11:38 | IP Logged Quote BeachBum

Damn, I better find new glasses…

__________________
Pete - X10 Oldie
Back to Top View BeachBum's Profile Search for other posts by BeachBum
 
sjvonstein
Groupie
Groupie


Joined: February 05 2010
Location: United States
Online Status: Offline
Posts: 75
Posted: May 20 2010 at 11:43 | IP Logged Quote sjvonstein

You're welcome.

lol@ BeachBum
Back to Top View sjvonstein's Profile Search for other posts by sjvonstein
 
MAWilsonPE
Newbie
Newbie
Avatar

Joined: May 30 2008
Location: United States
Online Status: Offline
Posts: 18
Posted: May 20 2010 at 11:48 | IP Logged Quote MAWilsonPE

Maybe it is the IF statement that does not like to return a negative value than the JUMP. Goto Label works.

What happens if the formula is set to Post instead of Immediate?
Back to Top View MAWilsonPE's Profile Search for other posts by MAWilsonPE
 
sjvonstein
Groupie
Groupie


Joined: February 05 2010
Location: United States
Online Status: Offline
Posts: 75
Posted: May 20 2010 at 12:05 | IP Logged Quote sjvonstein

It's possible that the jump command isn't accepting a negative. Jump seems relatively obsolete with GoTo commands being so easy to use and are not dependent on changing line numbers. I'm not clear on the difference between post/immediate. I only know that changing most of my macros functions to "POST" has solved many problems.
Back to Top View sjvonstein's Profile Search for other posts by sjvonstein
 
BeachBum
Super User
Super User
Avatar

Joined: April 11 2007
Location: United States
Online Status: Offline
Posts: 1880
Posted: May 20 2010 at 16:21 | IP Logged Quote BeachBum

OK, now that I have my glasses on try this for giggles.
If (ph_getvar_n(2,4) = 3, 999, -4)
Put a space before the dash.


__________________
Pete - X10 Oldie
Back to Top View BeachBum's Profile Search for other posts by BeachBum
 
MAWilsonPE
Newbie
Newbie
Avatar

Joined: May 30 2008
Location: United States
Online Status: Offline
Posts: 18
Posted: May 20 2010 at 18:11 | IP Logged Quote MAWilsonPE

OK, it seems that the following:
If(ph_getvar_n(2,4)=3,999, -4)
is the same as If([TEMP4]=3,999, -4)

I am using TEMP3 so that should be:
If(ph_getvar_n(2,3)=3,999, -4)

Not sure if this has an advantage over If([TEMP3]=3,999, -4)

I like the Goto Label, it works. It may be that PH does not like JUMP = -4

Thanks for all your help, I got it working w/ Goto Label

Edited by MAWilsonPE - May 20 2010 at 18:13
Back to Top View MAWilsonPE's Profile Search for other posts by MAWilsonPE
 
BeachBum
Super User
Super User
Avatar

Joined: April 11 2007
Location: United States
Online Status: Offline
Posts: 1880
Posted: May 20 2010 at 18:54 | IP Logged Quote BeachBum

Yep for some reason PH_GETVAR will always work and [xxxx] sometimes. I use GOTO and JUMP. Prefer GOTO in larger macros. Minus (-4) is working for me.

__________________
Pete - X10 Oldie
Back to Top View BeachBum's Profile Search for other posts by BeachBum
 

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