Page 1 of 1

Error on Line 45 - but only 36 lines of code

PostPosted: Sat Dec 17, 2022 3:39 pm
by davidimurray
Hi All

new to Uccnc and currently writing a macro for my spindle. When running my code I get an error saying expected ; on line 45. But i only have 36 lines of code.

Any ideas what this might be about as I'm struggling to debug.

Thanks

Dave

Re: Error on Line 45 - but only 36 lines of code

PostPosted: Sun Dec 18, 2022 3:45 am
by fsli
davidimurray wrote:When running my code I get an error saying expected ; on line 45. But i only have 36 lines of code.

When your macro runs, it is running inside of a C# class module. It's the additional lines of source code for the class module (which you can't see and can't control) that throw off the reported line number.

If the error had been on the very first line of your macro, that would be reported as line 10. So, an error on line 45 is actually being reported on the last line of your macro.

Re: Error on Line 45 - but only 36 lines of code

PostPosted: Sun Dec 18, 2022 2:18 pm
by davidimurray
That's great - thanks Frank

Re: Error on Line 45 - but only 36 lines of code

PostPosted: Sat Dec 24, 2022 8:37 pm
by fsli
David,

I was doing some reading and found that C# supports a #line directive that will change the line number reported by the compiler. So, as a quick example, let's say we force a compiler error by creating a macro with just this statement (mispelled Console intentionally):

Code: Select all
Concole.WriteLine("");

When you execute this macro, the compiler will report the error on line 10. As I previously said, that's because of overhead in how the macro is incorporated into a compileable class module. However, if you add a #line directive, like this:

Code: Select all
#line 1
Concole.WriteLine("");

Now the compiler will report the error on line 1. The #line directive resets the line number reference, so any errors occurring from that point on will correctly point to the macro line, without consideration for the other overhead. This still gets complicated if your macro includes an #Events tag. That's because there's no way to eliminate the overhead lines between the main macro body and the statements which follow the #Events tag. So, in this example:

Code: Select all
#line 1
Console.WriteLine("No error here");
#Events
private static void SyntaxError() { Concole.WriteLine(); }

The compiler now reports the error as happening on line 5, even though it's on the third line of the macro file. There are two lines of overhead that can't be ignored.

This is not supported in the Visual Basic compiler.

Re: Error on Line 45 - but only 36 lines of code

PostPosted: Sun Dec 25, 2022 12:55 pm
by ger21
I had an error the other day I couldn't find, so I just added a line with an intentional error so that I could track it down.
It can be tricky to find when a "missing ;" error is due to a spelling error.