Error on Line 45 - but only 36 lines of code

This is where you talk about Macros, show examples of your macro scripting and SHARE handy segments of script code as examples.

Error on Line 45 - but only 36 lines of code

Postby davidimurray » Sat Dec 17, 2022 3:39 pm

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
davidimurray
 
Posts: 2
Joined: Sun Nov 20, 2022 6:48 pm

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

Postby fsli » Sun Dec 18, 2022 3:45 am

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.
Frank
fsli
 
Posts: 95
Joined: Mon Jul 11, 2022 12:36 am

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

Postby davidimurray » Sun Dec 18, 2022 2:18 pm

That's great - thanks Frank
davidimurray
 
Posts: 2
Joined: Sun Nov 20, 2022 6:48 pm

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

Postby fsli » Sat Dec 24, 2022 8:37 pm

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.
Frank
fsli
 
Posts: 95
Joined: Mon Jul 11, 2022 12:36 am

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

Postby ger21 » Sun Dec 25, 2022 12:55 pm

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.
Gerry
UCCNC 2022 Screenset - http://www.thecncwoodworker.com/2022.html
ger21
 
Posts: 2676
Joined: Sat Sep 03, 2016 2:17 am


Return to Macros

Who is online

Users browsing this forum: No registered users and 1 guest