Hi Bob,
Have a look here
www.turnssoft.com/conditions.html#integer_variable and here
www.turnssoft.com/conditions.html#define_integer_variable for some info on math within MMM.
Here is a break down....
Math evaluations are available for both INTEGER and DECIMAL variables. Consider the following INTEGER VARIABLE example statements below that show all the available OPERATOR evaluation of:
Addition (+)
Subtraction (-)
Multiplication (*)
Division (/)
Is even
Is odd
Power of (^)
Modulus (%)
Equal to (=)
Not equal to (!=)
Greater than (>)
Greater than equal to (>=)
Less than (<)
Less than equal to (<=)
ADDITION example (+)
1 | IF | INTEGER VARIABLE | %INTEGER% | + | 2::=::%INTEGER1% | DELETE FILE | D:\Macro\%STRING%_%INTEGER1%.mmmacro
This reads - IF the INTEGER VARIABLE, %INTEGER%, + 2 does equal (=) the value of %INTEGER1% then DELETE the FILE located at D:\Marco\%STRING%_%INTEGER1%.mmmacro.
SUBTRACTION example (-)
1 | IF | INTEGER VARIABLE | %INTEGER% | - | %INTEGER1%::>=::%INTEGER1% | DEFINE INTEGER VARIABLE | %INTEGER%::*%INTEGER2%
This reads - IF the INTEGER VARIABLE, %INTEGER%, subtract (-) %INTEGER1% is greater or equal to (>=) the value of %INTEGER1% then DEFINE INTEGER VARIABLE, %INTEGER% to be the value of %INTEGER% multiple by (*) %INTEGER2%.
MULTIPLICATION example (*)
1 | IF | INTEGER VARIABLE | %INTEGER% | * | 2::<::100 | GOTO MACRO LINE | %RETURN%-5
This reads - IF the INTEGER VARIABLE, %INTEGER%, multiply by (*) 2 is less than (<) the value 100 then GOTO MACRO LINE number with the value of %RETURN%-5. More on the %RETURN% variable can found under the GOTO MACRO LINE section.
DIVISION example (/)
1 | IF | INTEGER VARIABLE | %INTEGER% | / | 5::!=::5 | DEFINE INTEGER VARIABLE | %INTEGER%::25
This reads - IF the INTEGER VARIABLE, %INTEGER%, divided by (/) 5 is not equal to (!=) the value 5 then DEFINE INTEGER VARIABLE, %INTEGER% to be the value of 25.
IS EVEN
1 | IF | INTEGER VARIABLE | %INTEGER% | IS EVEN | MOD 2 = 0 | DEFINE INTEGER VARIABLE | %INTEGER%::%INTEGER1%
This reads - IF the INTEGER VARIABLE %INTEGER% IS an EVEN number then DEFINE INTEGER VARIABLE to be the current value of the variable %INTEGER1%. So the current integer variable value is 2, this is a even number (MOD 2 = 0) and evaluates to true, so now define the value of %INTEGER% to be the value of the %INTEGER1% variable .
IS ODD
1 | IF | INTEGER VARIABLE | %INTEGER% | IS ODD | MOD 2 = 1 | DEFINE INTEGER VARIABLE | %INTEGER%::+1 | ELSE | 2 | IF | INTEGER VARIABLE | %INTEGER% | % | 2::=::0 | MESSAGE PROMPT | Value is EVEN::Even or Odd
This example is similar to the IS EVEN example above however it showcases an alternative via the ELSE statement using a MODULUS match function.
POWER OF example (^)
1 | IF | INTEGER VARIABLE | %INTEGER% | ^ | 3::<::100 | DEFINE INTEGER VARIABLE | %INTEGER%::+25
This reads - IF the INTEGER VARIABLE, %INTEGER%, to the power of (^) 3 is less than (<) the value 100 then DEFINE INTEGER VARIABLE, %INTEGER%to be the value of %INTEGER% + 25.
MODULUS example (%)
1 | IF | INTEGER VARIABLE | %INTEGER% | % | %INTEGER1%::=::%INTEGER2% | COPY TO CLIPBOARD | %INTEGER% | ELSE | 2 | RUN ACTION | DEFINE INTEGER VARIABLE | %INTEGER3%::%3
This reads - IF the INTEGER VARIABLE, %INTEGER%, mod (%) %INTEGER1% is equal to (=) the value %INTEGER2% then run the action to COPY TO CLIPBOARD the value of %INTEGER% or ELSE if the value is not equal to then DEFINE INTEGER VARIABLE, %INTEGER3% to be the value of %INTEGER3% % 3.
EQUAL example (=)
1 | IF | INTEGER VARIABLE | %INTEGER% | IS | 100 | DEFINE INTEGER VARIABLE | %INTEGER%::+150
-or-
1 | IF | INTEGER VARIABLE | %INTEGER% | = | 100 | DEFINE INTEGER VARIABLE | %INTEGER%::+150
This reads - IF the INTEGER VARIABLE %INTEGER4% IS 100 then DEFINE INTEGER VARIABLE, %INTEGER%, to be the current value + 150. So the current integer variable is 100, so this condition evaluates to true, so add 150, the value of %INTEGER% is now 350.
NOT EQUAL example (!=)
1 | IF | INTEGER VARIABLE | %INTEGER% | IS NOT | 100 | DEFINE INTEGER VARIABLE | %INTEGER%::-300
-or-
1 | IF | INTEGER VARIABLE | %INTEGER% | != | 100 | DEFINE INTEGER VARIABLE | %INTEGER%::-300
This reads - IF the INTEGER VARIABLE %INTEGER% IS NOT 100 then DEFINE INTEGER VARIABLE to be the current value - 300. So the current integer variable value is 350, and not 100 so this condition is true, now subtract that by 300. the value of %INTEGER% is now 50.
GREATER THAN example (>)
1 | IF | INTEGER VARIABLE | %INTEGER% | GREATER THAN | 10 | DEFINE INTEGER VARIABLE | %INTEGER%::*200
-or-
1 | IF | INTEGER VARIABLE | %INTEGER% | > | 10 | DEFINE INTEGER VARIABLE | %INTEGER%::*200
This reads - IF the INTEGER VARIABLE %INTEGER% IS GREATER THAN 10 then DEFINE INTEGER VARIABLE to be the current value * 200. So the current integer variable value is 50, this is greater than 10 - the condition is true, now multiply that by 200. the value of %INTEGER% is now 10000.
GREATER THAN EQUAL TO example (>=)
1 | IF | INTEGER VARIABLE | %INTEGER% | GREATER THAN EQUAL TO | 10000 | DEFINE INTEGER VARIABLE | %INTEGER%::/2
-or-
1 | IF | INTEGER VARIABLE | %INTEGER% | >= | 10000 | DEFINE INTEGER VARIABLE | %INTEGER%::/2
This reads - IF the INTEGER VARIABLE %INTEGER% IS GREATER THAN or EQUAL TO 10000 then DEFINE INTEGER VARIABLE to be the current value / 2. So the current integer variable value is 10000, this is equal to 10000 and evaluates to true, so now divide that by 2. the value of %INTEGER% is now 5000.
LESS THAN example (<)
1 | IF | INTEGER VARIABLE | %INTEGER% | LESS THAN | 10000 | DEFINE INTEGER VARIABLE | %INTEGER%::-99999
-or-
1 | IF | INTEGER VARIABLE | %INTEGER% | < | 10000 | DEFINE INTEGER VARIABLE | %INTEGER%::-99999
This reads - IF the INTEGER VARIABLE %INTEGER% IS LESS THAN 10000 then DEFINE INTEGER VARIABLE to be the current value - 99999. So the current integer variable value is 5000, this is less than to 10000 and evaluates to true, so now subtract that by 99999. the value of %INTEGER% is now -94999.
LESS THAN EQUAL TO example (<=)
1 | IF | INTEGER VARIABLE | %INTEGER% | LESS THAN EQUAL TO | 1 | RUN PROGRAM | c:\Batch\calculateresults.bat
-or-
1 | IF | INTEGER VARIABLE | %INTEGER% | <= | 1 | RUN PROGRAM | c:\Batch\calculateresults.bat
This reads - IF the INTEGER VARIABLE %INTEGER% IS LESS THAN or EQUAL TO 1 then RUN the PROGRAM located at C:\Batch\calcualteresults.bat. So the current integer variable value is -94999, this is less than to 1 and evaluates to true, so now run the program c:\Batch\calculateresults.bat
RUN ACTION | DEFINE INTEGER VARIABLE | %INTEGER%::=100 Declaration - %INTEGER% = 100
RUN ACTION | DEFINE INTEGER VARIABLE | %INTEGER%::+100 Addition - %INTEGER% + 100
RUN ACTION | DEFINE INTEGER VARIABLE | %INTEGER%::-100 Subtraction - %INTEGER% - 100
RUN ACTION | DEFINE INTEGER VARIABLE | %INTEGER%::/100 Division - %INTEGER% / 100
RUN ACTION | DEFINE INTEGER VARIABLE | %INTEGER%::*100 Multiplication - %INTEGER% * 100
RUN ACTION | DEFINE INTEGER VARIABLE | %INTEGER%::%2 Modulus - %INTEGER% MOD 2
RUN ACTION | DEFINE INTEGER VARIABLE | %INTEGER%::^5 Power of - %INTEGER% to the power of 5
RUN ACTION | DEFINE INTEGER VARIABLE | %INTEGER%::%INTEGER1% %INTEGER% equals the value of %INTEGER1%
RUN ACTION | DEFINE INTEGER VARIABLE | %INTEGER%::%RANDOM_200-250% %INTEGER% equals a random between 200 and 250
RUN ACTION | DEFINE INTEGER VARIABLE | %INTEGER%::%STRING% %INTEGER% equals the value of %STRING% (must be a number)
RUN ACTION | DEFINE INTEGER VARIABLE | %INTEGER%::%CLIPBOARD% %INTEGER% equals the value of %CLIPBOARD% (must be a number)
RUN ACTION | DEFINE INTEGER VARIABLE | %INTEGER%::XOR10 XOR - %INTEGER% XOR 10
RUN ACTION | DEFINE INTEGER VARIABLE | %INTEGER%::MAX%INTEGER1% MAX - %INTEGER% equals the highest value of itself compare %INTEGER1%
RUN ACTION | DEFINE INTEGER VARIABLE | %INTEGER%::MIN50 MIN - %INTEGER% equals the lowest value of itself compare 50
RUN ACTION | DEFINE INTEGER VARIABLE | %INTEGER%::SIGN SIGN - %INTEGER% equals math SIGN value of itself
RUN ACTION | DEFINE INTEGER VARIABLE | %INTEGER%::SQRT SQRT- %INTEGER% equals the value squared
RUN ACTION | DEFINE INTEGER VARIABLE | %INTEGER%::SQRT%INTEGER1% SQRT- %INTEGER% equals the value squared by %INTEGER1%
RUN ACTION | DEFINE INTEGER VARIABLE | %INTEGER%::POW7 POW- %INTEGER% equals the %INTEGER% to the power of 7