|
Post by arcylix on May 17, 2021 19:02:26 GMT
I have a macro that does work, but I get the error listed below. It doesn't seem to mess anything up, but I'm curious why it produces the error. Any thoughts?
27 | IF | INTEGER VARIABLE | %INTEGER2% | GREATER THAN | %INTEGER3% | CLEAR | AND | 27 | RUN ACTION | DEFINE INTEGER VARIABLE | %INTEGER2%::1 | AND | 27 | RUN ACTION | DEFINE INTEGER VARIABLE | %INTEGER%::180 | ELSE | 27 | CONTINUE - An unexpected error occured processing this line: Index was outside the bounds of the array.
N.B. - "occured" is misspelled. It should be "occurred".
|
|
|
Post by Steve on Jun 5, 2021 20:56:40 GMT
Hi arcylix Firstly, sorry for the delay on the reply here. This thread has been up for a couple of few weeks now and I do appreciate you taking the time to create an account and share your comments with the MMM community here. It looks like you've got a syntax error here. This: 27 | IF | INTEGER VARIABLE | %INTEGER2% | GREATER THAN | %INTEGER3% | CLEAR | AND | 27 | RUN ACTION | DEFINE INTEGER VARIABLE | %INTEGER2%::1 | AND | 27 | RUN ACTION | DEFINE INTEGER VARIABLE | %INTEGER%::180 | ELSE | 27 | CONTINUE should be: 27 | IF | INTEGER VARIABLE | %INTEGER2% | GREATER THAN | %INTEGER3% | CLEAR | AND | 27 | RUN ACTION | DEFINE INTEGER VARIABLE | %INTEGER2%::1 | AND | 27 | RUN ACTION | DEFINE INTEGER VARIABLE | %INTEGER%::180 | ELSE | 27 | RUN ACTION | CONTINUEbut it is effectively this: 27 | IF | INTEGER VARIABLE | %INTEGER2% | GREATER THAN | %INTEGER3% | CLEAR | AND | 27 | RUN ACTION | DEFINE INTEGER VARIABLE | %INTEGER2%::1 | AND | 27 | RUN ACTION | DEFINE INTEGER VARIABLE | %INTEGER%::180 You don't need the final else statement for CONTINUE in your statement. If the 'IF' condition were to be false you would be moving to line 28 which is the same as the 'CONTINUE' action. Why did it produce the error? MMM has some real strict syntax checking. It is expecting the 27 | RUN ACTION | CONTINUE but it gets 27 | CONTINUE.
At run time MMM loads the statement reading it into an event array where it is expecting the syntax to be a specific length. When it's not that length we get "Index was outside the bounds of the array." Which is really saying "This macro line has incorrect syntax.". Hope that helps.
|
|
|
Post by arcylix on Jun 7, 2021 15:20:39 GMT
Ah, that makes sense. I will point out, however, that I was using the examples found here.CONTINUE action is used for macro flow control.
Consider the CONTINUE example statement below taken from a macro condition:
1 | IF | FILE | C:\rescue.log | EXIST | CONTINUE
This reads - IF the FILE c:\rescue.log does EXIST then CONTINUE the macro. So if the file is present on the system at the time of the condition evaluation then continue running the macro. The macro will only continue if the file exists.
Note: Continue is a useful action to apply if you want to wait until an object is evaluated as true. Take the example above, this will only evaluate and continue to the next macro line once the file c:\rescue.log does exist.
Consider this CONTINUE example statement below taken from a macro PIXEL condition:
1 | IF | PIXEL COLOR | At Location [X:2768 Y:602] | CHANGES::2::0::200 | CONTINUE
This reads - IF the PIXEL COLOR at mouse location X 2768 and Y 602 does change 2 times, with 0 timeout value, and with a 200 milliseconds delay between changes, then CONTINUE the macro.
Consider this CONTINUE statement as a further example:
1 | IF | FILE | C:\rescue.log | FILE CONTAINS STRING | Hello | CONTINUE
This reads - IF the FILE c:\rescue.log does CONTAIN the STRING 'Hello' then CONTINUE. Only if the word 'Hello' is within the file will the macro continue. The macro will continue to read the file on a loop until the word Hello is found. Only then will the macro continue. I don't know if it was an oversight, or if the ELSE condition makes it require RUN ACTION, but I will modify it based off what your suggestions are. Thanks for the assist, and I'm quite happy with MMM being my go-to at work. Cuts out over an hour of day of manual labor!
|
|
|
Post by Steve on Jun 7, 2021 20:40:33 GMT
Thanks arcylix . I think i see where the confusion is. The CONTINUE doco examples you point out are the correct syntax for continue and show some typical use cases. The difference here is your use of the ELSE statement. Your line 27 has continue evaluating after an ELSE statement. MMM is expecting a full condition statement after an ELSE. ELSE ELSE is used with either IF or the IF NOT conditions to allow further evaluation to continue if the condition does not evaluate to TRUE. To put it another way, ELSE can be thought of as 'otherwise do this' if the first condition fails. An ELSE condition can not be used when the initial condition has the CONTINUE action. This is because with the CONTINUE action the condition must evaluate to TRUE prior to continuing the macro.
Consider the following example: 1 | IF | FILE | C:\MMM\Skip.mmmacro | EXIST | GOTO MACRO LINE | 5 | ELSE | 1 | RUN ACTION | GOTO MACRO LINE | 2
So if the file C:\MMM\Skip.mmmacro does EXIST then the macro will GOTO MACRO LINE 5 but if the file does not exist then RUN the ACTION to GOTO MACRO LINE 2.
ELSE can further be used to evaluate subsequent conditions. For example: IF | FILE | C:\MMM\Skip.mmmacro | EXIST | GOTO MACRO LINE | 5 | ELSE | 1 | IF | FILE | C:\MMM\Skip2.mmmacro | EXIST | GOTO MACRO LINE | 10
Here if the first condition evaluates to false, the file does not exist, then the second condition will be evaluated.
Note: To add ELSE to a condition select the 'ELSE' checkbox option within the 'Add Condition' window. It is best to do this after you set your first condition. For example:
Create your initial IF or IF NOT condition - do not click ok. Check the 'ELSE' checkbox. Now select either IF, IF NOT, or RUN ACTION condition - This will add the condition after the ELSE. [LINE #] | [FIRST CONDITION] | ELSE | [LINE #] | [CONDITION] or for a RUN ACTION condition: [LINE #] | [FIRST CONDITION] | ELSE | [LINE #] | [ACTION] Select your OBJECT - this will add an object condition after the condition. [LINE #] | [FIRST CONDITION] | ELSE | [LINE #] | [CONDITION] | [OBJECT] Now complete the ELSE line by selecting the OPERATOR and ACTION. [LINE #] | [FIRST CONDITION] | ELSE | [LINE #] | [CONDITION] | [OBJECT] | [OPERATOR] | [ACTION] It is best to follow this procedure for each ELSE condition added.
|
|