Page 1 of 1
Macro script error

Posted:
Tue Apr 28, 2020 9:04 pm
by loesch
I present my back for the floggings that will come, but I'm new to C# and writing macros. I have a simple message box macro which only has 11 lines. When I try to run it, errorlog says I have an error in line 18. So how do I use the line numbers to debug my code? I have looked at it carefully, but I must be missing something. The macro and errorlog are attached for those that want to look at it, but my question is with how the compiler numbers lines.
MessageBoxButtons buttons = MessageBoxButtons.YesNo;
DialogResult result = MessageBox.Show("Has probe been removed to a safe location?","Probe SAFE", buttons);
if (result == DialogResult.No) {
exec.Stop();
return;
}
else {
exec.Code("G1 F300 Z20");
While(exec.IsMoving()){}
exec.Wait(1000);
}
UCCNC macro compiler error log file
--------------------------------------
Last error dated: 4/28/2020 4:56:27 PM
In macro: M20004
--------------------------------------
CS1002 | in line: 18 | error text: ; expected
--------------------------------------
Re: Macro script error

Posted:
Tue Apr 28, 2020 10:51 pm
by beefy
Will this fix it:
While(exec.IsMoving();){}
Re: Macro script error

Posted:
Tue Apr 28, 2020 11:22 pm
by cncdrive
Yes you forgot a ; after the function call.
You could use Visual Basic language if you don't like this.

Just put #VB in the very first line of the macro to program in VB. (I've mentiond this because maybe you did not know and you might like VB better than C#)
Re: Macro script error

Posted:
Wed Apr 29, 2020 3:16 pm
by loesch
Well, I tried adding a ; after the function call as beefy recommended, with no change. Get the same error of expecting a ; in line 18 (but there are only 11 lines of code in the macro). Also, I have several other macros which use the exact same "While(exec.IsMoving()){}" without the recommended ; and they all work fine (no errors). Something else seems to be going one. Will keep plugging away.
Is there anyway of seeing in UCCNC a debugging screen that actually shows the line of code that it doesn't like other than just a line number which doesn't seem to correlate with actual code?
Re: Macro script error

Posted:
Wed Apr 29, 2020 3:31 pm
by cncdrive
Sorry, it was too late night for me when I replied this.

No, you do not have to put ; there.
The issue is that you wrote the while with capital W, it should be not While, but while.
Re: Macro script error

Posted:
Wed Apr 29, 2020 4:20 pm
by Vmax549
What they are not telling you is there is a 10 line offset in teh error reporting. So if it said line 18 it would really be around line 8 of teh macro.
Just a thought , (;-) TP
Re: Macro script error

Posted:
Wed Apr 29, 2020 11:55 pm
by loesch
Thank you to all that offered a helping hand. This brought back my old fortran programming days where you can stare directly at an error for days and not see something so simple. Thanks to cncdrive for pointing out the caps error. Stay safe.
Re: Macro script error

Posted:
Thu Apr 30, 2020 10:59 pm
by beefy
loesch wrote:This brought back my old fortran programming days where you can stare directly at an error for days and not see something so simple.
Ha ha, dead right, been down that road several times
