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.
Cannot do negative multiplication
Moderators: JRL, Dorian (MJT support)
- Bob Hansen
- Automation Wizard
- Posts: 2475
- Joined: Tue Sep 24, 2002 3:47 am
- Location: Salem, New Hampshire, US
- Contact:
Re: Cannot do negative multiplication
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.
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]
[email protected]
- Bob Hansen
- Automation Wizard
- Posts: 2475
- Joined: Tue Sep 24, 2002 3:47 am
- Location: Salem, New Hampshire, US
- Contact: