Cannot do negative multiplication

Technical support and scripting issues

Moderators: Dorian (MJT support), JRL

Post Reply
User avatar
Bob Hansen
Automation Wizard
Posts: 2475
Joined: Tue Sep 24, 2002 3:47 am
Location: Salem, New Hampshire, US
Contact:

Cannot do negative multiplication

Post by Bob Hansen » Tue Oct 22, 2002 8:07 am

Can someone suggest how to do negative multiplication on a variable?

I discovered that this could not be done (by me). I wanted to toggle a status every time I go through a routine. I set the Status=1, and then multiply Status by -1. If the Status is greater than 0, do action A, else do Action B. If I multiply Status by any positive number, I get the correct result. If I multiply by a negative number, I get a string for the result: -1*Status.

Simplified example of routine to alternately do Actions A and B:
======================================
Let>Status=1

Label>Toggle_Actions
...
...
...
//Next line should toggle between -1 and +1 with each run
Let>Status=-1*Status
If>Status>0,Action_A,Action_B

Label>Action_A
....
....
....
If>TrueCondition,Toggle_Actions,End

Label>Action_B
...
...
...
If>TrueCondition,Toggle_Actions,End
...
...
...
Label>End
=============================
To solve the problem in my script, I have just added lines for toggling the Status valuet in section Action_A and again in section Action_B, but I am more concerned about the inability to multiply by a negative.

Perhaps we could see a new command like "Sign>variable" which would toggle the sign of a number, doing the same as multiplying by -1? Positives would change to negatives, and negatives would change to positives.

User avatar
support
Automation Wizard
Posts: 1450
Joined: Sat Oct 19, 2002 4:38 pm
Location: London
Contact:

Re: Cannot do negative multiplication

Post by support » Wed Oct 23, 2002 10:34 am

Hi,

It doesn't like the -1 in there, but works with a variable, so the solution is to set a constant variable to -1 and use it in the calc:

Let>x=-1
Let>Status=x*Status

Not sure why, but will look into it and if a bug will request a fix. But the above is a simple enough workaround.
MJT Net Support
[email protected]

User avatar
Bob Hansen
Automation Wizard
Posts: 2475
Joined: Tue Sep 24, 2002 3:47 am
Location: Salem, New Hampshire, US
Contact:

Post by Bob Hansen » Wed Oct 23, 2002 2:24 pm

Great idea. Thanks for a simple solution.

I hate it when the obvious is right in front of me and I can't see it.

Post Reply
Sign up to our newsletter for free automation tips, tricks & discounts