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

Joined: December 25 2011
Location: United States
Online Status: Offline
Posts: 8
Posted: January 16 2012 at 12:54 | IP Logged Quote ConPro

Please excuse the newbie cry for help, I'm sure it is easy (everything is when you know how to do it). Here is what I am trying to do:
Macro that reads a value from a global variable. Based on the content of that variable, execute a macro and terminate base macro.

I tried
10 Jump . . . Case {MB_OCCUPIED} = True then 1 else 4
20 Label . . . True
30 Macro . . . mMBOCCUPIED
40 GoTo Label . . . END
50 Label . . . False
60 macro . . . mMBEmpty
70 Label . . .END

Always drop through both macro calls regardless of the value in MB_OCCUPIED. Anyone with a minute please point me in the right direction.

Thanks
Tom
Back to Top View ConPro's Profile Search for other posts by ConPro Visit ConPro's Homepage
 
dhoward
Admin Group
Admin Group
Avatar

Joined: June 29 2001
Location: United States
Online Status: Offline
Posts: 4447
Posted: January 16 2012 at 17:04 | IP Logged Quote dhoward

Tom,

Since you posted pseudocode, it may be a problem in case statement. Looking at what you've posted, this is probably how I would handle it.

10 Goto Label ph_getglobal_s("MB_OCCUPIED")
20 End Macro
30 Label True
40 Macro Immediate MBOCCUPIED
50 End Macro
60 Label False
70 Macro Immediate MBEMPTY

What this would do is pull the actual value from the MB_OCCUPIED global variable and Goto the label based upon the value. If the MB_OCCUPIED global does not contain the string "True" or "False", the goto label command passes control to the next line which is an end macro command. So unexpected values just cause the macro to terminate. One thing to note here is that the Jump macro command does not require labels and will jump a specified number of lines forward or backward (neg numbers). Jumps work great for tight loops but can be a problem for maintenance if you add/modify your macro and now have to adjust all the jump values. Label and Goto Label work together. A very important point is that the Label command takes text value WITHOUT quotes. Its not a formula so isnt evaluated. The Goto Label command IS a formula so you need to surround your literal labels with quotes so its a string.

Anyways, the rest of the macro should be self explanatory and I believe will work out for you .

Hope this helps,

Dave.
Back to Top View dhoward's Profile Search for other posts by dhoward Visit dhoward's Homepage
 
ConPro
Newbie
Newbie
Avatar

Joined: December 25 2011
Location: United States
Online Status: Offline
Posts: 8
Posted: January 18 2012 at 11:17 | IP Logged Quote ConPro

Thanks that works perfectly. I did discover another gotcha and was wondering if anyone had a simple solution (I have some complex ones but I am hoping to KISS).

The trigger that runs this macro is set on the Global variable change. I am updating this variable from an external software. so far so good everything works as desired, including putting multiple status options for more then 2 branches.

The issue comes in if I set the variable to a value it already is. (IE I set the MB_OCCUPIED to true and it already was true.) it runs the trigger again. Is this correct behavior, or is there operator error in here? any simple workarounds?

Thanks
Tom
Back to Top View ConPro's Profile Search for other posts by ConPro Visit ConPro's Homepage
 
BeachBum
Super User
Super User
Avatar

Joined: April 11 2007
Location: United States
Online Status: Offline
Posts: 1880
Posted: January 18 2012 at 11:47 | IP Logged Quote BeachBum

That is the way it works. I would check in the Boolean field if the variable is the same if so set +0 if different then +1. That will fire the trigger only when different. Try sticking this in Boolean of the trigger.    [TEMP5] <> [TEMP10]

__________________
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