<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: To retrieve Line number in the Code in Inventor Programming Forum</title>
    <link>https://forums.autodesk.com/t5/inventor-programming-forum/to-retrieve-line-number-in-the-code/m-p/8091179#M87425</link>
    <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/2129088"&gt;@RoyWickrama_RWEI&lt;/a&gt;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For iLogic, you could try the below:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;Sub Main
Dim i As Long

On Error Goto Whoa

10:    i = "Sid"
20:    Exit Sub
Whoa:
    MessageBox.Show("Error on Line : " &amp;amp; Erl)

End Sub&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Regards,&lt;/P&gt;
&lt;P&gt;Sajith&lt;/P&gt;</description>
    <pubDate>Tue, 26 Jun 2018 06:38:36 GMT</pubDate>
    <dc:creator>sajith_subramanian</dc:creator>
    <dc:date>2018-06-26T06:38:36Z</dc:date>
    <item>
      <title>To retrieve Line number in the Code</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-forum/to-retrieve-line-number-in-the-code/m-p/8087362#M87422</link>
      <description>&lt;P&gt;I am thinking to incorporate (sometimes) the line number in the message box.&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Line Number.png" style="width: 466px;"&gt;&lt;img src="https://forums.autodesk.com/t5/image/serverpage/image-id/515468i4335C3240BEE2E63/image-size/large?v=v2&amp;amp;px=999" role="button" title="Line Number.png" alt="Line Number.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;I request help.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 23 Jun 2018 19:46:51 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-forum/to-retrieve-line-number-in-the-code/m-p/8087362#M87422</guid>
      <dc:creator>RoyWickrama_RWEI</dc:creator>
      <dc:date>2018-06-23T19:46:51Z</dc:date>
    </item>
    <item>
      <title>Re: To retrieve Line number in the Code</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-forum/to-retrieve-line-number-in-the-code/m-p/8088898#M87423</link>
      <description>&lt;P&gt;Hi &lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/2129088"&gt;@RoyWickrama_RWEI&lt;/a&gt;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You could probably use something similar as shown in the below link:&lt;/P&gt;
&lt;P&gt;&lt;A href="https://stackoverflow.com/questions/16398261/how-to-check-which-line-of-vba-code-is-causing-errors" target="_blank"&gt;https://stackoverflow.com/questions/16398261/how-to-check-which-line-of-vba-code-is-causing-errors&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Regards,&lt;/P&gt;
&lt;P&gt;Sajith&lt;/P&gt;</description>
      <pubDate>Mon, 25 Jun 2018 09:01:29 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-forum/to-retrieve-line-number-in-the-code/m-p/8088898#M87423</guid>
      <dc:creator>sajith_subramanian</dc:creator>
      <dc:date>2018-06-25T09:01:29Z</dc:date>
    </item>
    <item>
      <title>Re: To retrieve Line number in the Code</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-forum/to-retrieve-line-number-in-the-code/m-p/8090418#M87424</link>
      <description>&lt;P&gt;Tanks for the reply.&lt;/P&gt;&lt;P&gt;I would request you&amp;nbsp;provide me with a bit of coding in case it is possible to do with iLogic.&lt;/P&gt;&lt;P&gt;Thanks.&lt;/P&gt;</description>
      <pubDate>Mon, 25 Jun 2018 19:25:20 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-forum/to-retrieve-line-number-in-the-code/m-p/8090418#M87424</guid>
      <dc:creator>RoyWickrama_RWEI</dc:creator>
      <dc:date>2018-06-25T19:25:20Z</dc:date>
    </item>
    <item>
      <title>Re: To retrieve Line number in the Code</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-forum/to-retrieve-line-number-in-the-code/m-p/8091179#M87425</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/2129088"&gt;@RoyWickrama_RWEI&lt;/a&gt;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For iLogic, you could try the below:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;Sub Main
Dim i As Long

On Error Goto Whoa

10:    i = "Sid"
20:    Exit Sub
Whoa:
    MessageBox.Show("Error on Line : " &amp;amp; Erl)

End Sub&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Regards,&lt;/P&gt;
&lt;P&gt;Sajith&lt;/P&gt;</description>
      <pubDate>Tue, 26 Jun 2018 06:38:36 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-forum/to-retrieve-line-number-in-the-code/m-p/8091179#M87425</guid>
      <dc:creator>sajith_subramanian</dc:creator>
      <dc:date>2018-06-26T06:38:36Z</dc:date>
    </item>
    <item>
      <title>Re: To retrieve Line number in the Code</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-forum/to-retrieve-line-number-in-the-code/m-p/8092292#M87426</link>
      <description>&lt;P&gt;Thanks for the reply.&lt;/P&gt;&lt;P&gt;I&amp;nbsp; thought we don't specify the&amp;nbsp;line numbers but&amp;nbsp;code itself and will output the line number: is it possible?&lt;/P&gt;&lt;P&gt;Thanks!&lt;/P&gt;&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/4069635"&gt;@sajith_subramanian&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/2129088"&gt;@RoyWickrama_RWEI&lt;/a&gt;,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;For iLogic, you could try the below:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;Sub Main
Dim i As Long

On Error Goto Whoa

10:    i = "Sid"
20:    Exit Sub
Whoa:
    MessageBox.Show("Error on Line : " &amp;amp; Erl)

End Sub&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Sajith&lt;/P&gt;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 26 Jun 2018 14:50:59 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-forum/to-retrieve-line-number-in-the-code/m-p/8092292#M87426</guid>
      <dc:creator>RoyWickrama_RWEI</dc:creator>
      <dc:date>2018-06-26T14:50:59Z</dc:date>
    </item>
    <item>
      <title>Re: To retrieve Line number in the Code</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-forum/to-retrieve-line-number-in-the-code/m-p/8093982#M87427</link>
      <description>&lt;P&gt;You would need to specify the line numbers. I haven't tried it out myself, but i found an online discussion on a similar topic:&lt;/P&gt;
&lt;P&gt;&lt;A href="https://stackoverflow.com/questions/35459541/adding-line-numbers-to-vba-code-microsoft-access-2016" target="_blank"&gt;https://stackoverflow.com/questions/35459541/adding-line-numbers-to-vba-code-microsoft-access-2016&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Maybe it could be of some assistance to you.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Regards,&lt;/P&gt;
&lt;P&gt;Sajith&lt;/P&gt;</description>
      <pubDate>Wed, 27 Jun 2018 06:36:17 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-forum/to-retrieve-line-number-in-the-code/m-p/8093982#M87427</guid>
      <dc:creator>sajith_subramanian</dc:creator>
      <dc:date>2018-06-27T06:36:17Z</dc:date>
    </item>
    <item>
      <title>Re: To retrieve Line number in the Code</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-forum/to-retrieve-line-number-in-the-code/m-p/12156542#M87428</link>
      <description>&lt;P&gt;I do see this is pretty old thread ... yet not marked as solved&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I would recommend you pay attention at the 'Tip #19' of the AU-class '&lt;A href="https://www.autodesk.com/autodesk-university/class/iLogic-25-Tips-and-Tricks-Boost-Octane-your-Inventor-Automation-2022" target="_blank" rel="noopener"&gt;iLogic: 25 Tips and Tricks to Boost the Octane in your Inventor Automation&lt;/A&gt;'.&lt;/P&gt;&lt;P&gt;In fact the snippet returns the code-line-number next to 'End Try' line (which is enough to localize the error).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Dear&amp;nbsp;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/105031"&gt;@Curtis_W&lt;/a&gt; I do not see the code snippet of Tip#19 at 'Code Examples' subfolder within&amp;nbsp;&lt;A href="https://static.au-uw2-prd.autodesk.com/Class_Material_MFG501293_x_Waguespack.zip" target="_blank" rel="noopener"&gt;Class_Material_MFG501293_x_Waguespack.zip&amp;nbsp;&lt;/A&gt;&lt;/P&gt;&lt;P&gt;I wonder whether it should be like this or I'm missing something?&lt;/P&gt;</description>
      <pubDate>Tue, 08 Aug 2023 11:36:37 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-forum/to-retrieve-line-number-in-the-code/m-p/12156542#M87428</guid>
      <dc:creator>Maxim-CADman77</dc:creator>
      <dc:date>2023-08-08T11:36:37Z</dc:date>
    </item>
    <item>
      <title>Re: To retrieve Line number in the Code</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-forum/to-retrieve-line-number-in-the-code/m-p/12156609#M87429</link>
      <description>&lt;P&gt;Hi &lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/572109"&gt;@Maxim-CADman77&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;See this example for getting the line of an error.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;SPAN&gt;Sub&lt;/SPAN&gt; &lt;SPAN&gt;Main&lt;/SPAN&gt;

	&lt;SPAN&gt;Try&lt;/SPAN&gt;
		&lt;SPAN&gt;Parameter&lt;/SPAN&gt;(&lt;SPAN&gt;"Foo"&lt;/SPAN&gt;) = 4 &lt;SPAN&gt;'generates an error&lt;/SPAN&gt;
	&lt;SPAN&gt;Catch&lt;/SPAN&gt; &lt;SPAN&gt;ex&lt;/SPAN&gt; &lt;SPAN&gt;As&lt;/SPAN&gt; &lt;SPAN&gt;Exception&lt;/SPAN&gt;
		&lt;SPAN&gt;Call&lt;/SPAN&gt; &lt;SPAN&gt;HandleErrors&lt;/SPAN&gt;(&lt;SPAN&gt;ex&lt;/SPAN&gt;)
	&lt;SPAN&gt;End&lt;/SPAN&gt; &lt;SPAN&gt;Try&lt;/SPAN&gt;

&lt;SPAN&gt;End&lt;/SPAN&gt; &lt;SPAN&gt;Sub&lt;/SPAN&gt;

&lt;SPAN&gt;Sub&lt;/SPAN&gt; &lt;SPAN&gt;HandleErrors&lt;/SPAN&gt;(&lt;SPAN&gt;ex&lt;/SPAN&gt; &lt;SPAN&gt;As&lt;/SPAN&gt; &lt;SPAN&gt;Exception&lt;/SPAN&gt;)

	&lt;SPAN&gt;oStackTrace&lt;/SPAN&gt; = &lt;SPAN&gt;ex&lt;/SPAN&gt;.&lt;SPAN&gt;StackTrace&lt;/SPAN&gt;
	&lt;SPAN&gt;iPos&lt;/SPAN&gt; = &lt;SPAN&gt;InStr&lt;/SPAN&gt;(&lt;SPAN&gt;oStackTrace&lt;/SPAN&gt;, &lt;SPAN&gt;iLogicVb&lt;/SPAN&gt;.&lt;SPAN&gt;RuleName&lt;/SPAN&gt;)
	&lt;SPAN&gt;oErrorRuleLine&lt;/SPAN&gt; = &lt;SPAN&gt;Mid&lt;/SPAN&gt;(&lt;SPAN&gt;oStackTrace&lt;/SPAN&gt;, &lt;SPAN&gt;iPos&lt;/SPAN&gt;, &lt;SPAN&gt;Len&lt;/SPAN&gt;(&lt;SPAN&gt;oStackTrace&lt;/SPAN&gt;) -&lt;SPAN&gt;iPos&lt;/SPAN&gt; + 1)
	&lt;SPAN&gt;oErrorRuleLine&lt;/SPAN&gt; = &lt;SPAN&gt;Replace&lt;/SPAN&gt;(&lt;SPAN&gt;oErrorRuleLine&lt;/SPAN&gt;, &lt;SPAN&gt;iLogicVb&lt;/SPAN&gt;.&lt;SPAN&gt;RuleName&lt;/SPAN&gt; &amp;amp; &lt;SPAN&gt;".vb:"&lt;/SPAN&gt;, &lt;SPAN&gt;""&lt;/SPAN&gt;)
	&lt;SPAN&gt;Logger&lt;/SPAN&gt;.&lt;SPAN&gt;Error&lt;/SPAN&gt;(&lt;SPAN&gt;"Error at: "&lt;/SPAN&gt; &amp;amp; &lt;SPAN&gt;oErrorRuleLine&lt;/SPAN&gt;)
	&lt;SPAN&gt;Logger&lt;/SPAN&gt;.&lt;SPAN&gt;Info&lt;/SPAN&gt;(&lt;SPAN&gt;ex&lt;/SPAN&gt;.&lt;SPAN&gt;Message&lt;/SPAN&gt;)
&lt;SPAN&gt;End&lt;/SPAN&gt; &lt;SPAN&gt;Sub&lt;/SPAN&gt;&lt;/PRE&gt;
&lt;P&gt;Result:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Curtis_Waguespack_0-1691496268024.png" style="width: 600px;"&gt;&lt;img src="https://forums.autodesk.com/t5/image/serverpage/image-id/1250586iF4C62F1AE92B1B57/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Curtis_Waguespack_0-1691496268024.png" alt="Curtis_Waguespack_0-1691496268024.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 08 Aug 2023 13:00:32 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-forum/to-retrieve-line-number-in-the-code/m-p/12156609#M87429</guid>
      <dc:creator>Curtis_W</dc:creator>
      <dc:date>2023-08-08T13:00:32Z</dc:date>
    </item>
    <item>
      <title>Re: To retrieve Line number in the Code</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-forum/to-retrieve-line-number-in-the-code/m-p/12156731#M87430</link>
      <description>&lt;P&gt;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/2129088"&gt;@RoyWickrama_RWEI&lt;/a&gt;,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Do you need the line number or is that just to help debug?&lt;/P&gt;&lt;P&gt;Since 2020 I have been using Visual Studio to debug iLogic code.&lt;/P&gt;&lt;P&gt;See this post by Mike Deck:&lt;/P&gt;&lt;P&gt;&lt;A href="https://modthemachine.typepad.com/my_weblog/2019/12/using-visual-studio-to-debug-ilogic-rules.html" target="_blank" rel="noopener"&gt;https://modthemachine.typepad.com/my_weblog/2019/12/using-visual-studio-to-debug-ilogic-rules.html&lt;/A&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I adapted Mike's code when we upgraded to Inventor 2022 and VS2022.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Hope this is helpful.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Jerry&lt;/P&gt;</description>
      <pubDate>Tue, 08 Aug 2023 12:41:00 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-forum/to-retrieve-line-number-in-the-code/m-p/12156731#M87430</guid>
      <dc:creator>JBerns</dc:creator>
      <dc:date>2023-08-08T12:41:00Z</dc:date>
    </item>
    <item>
      <title>Re: To retrieve Line number in the Code</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-forum/to-retrieve-line-number-in-the-code/m-p/12157146#M87431</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/105031"&gt;@Curtis_W&lt;/a&gt;.&amp;nbsp; I like the idea of extracting the error line number from the &lt;A href="https://learn.microsoft.com/en-us/dotnet/api/system.exception.stacktrace?view=net-7.0" target="_blank" rel="noopener"&gt;Exception.StackTrace&lt;/A&gt; String, I know I saw this posted somewhere else before too, which is likely where I got the idea from, but I had to use a different version of that technique to get it to work more reliably for me.&amp;nbsp; Sometimes when it looks for the rule name, it does not find a match, because it sees certain common symbols differently.&amp;nbsp; For instance, some of my rules have the characters "(" &amp;amp; ")" in their names, and those show up as "_" (underscore) in the StackTrace, causing it to not be recognized as the name of the rule.&amp;nbsp; So I eliminated the rule name and just used the ".vb:line " text as the search target, and that seemed to clear up the failures for me.&lt;/P&gt;
&lt;P&gt;That being said, here is the slightly different routine I had been using (which was likely based on that code, or one like it).&lt;/P&gt;
&lt;LI-CODE lang="general"&gt;Sub LogError(oEx As Exception)
	Dim sST As String = oEx.StackTrace
	Dim i As Integer = InStr(StrReverse(sST), ".vb:line ")
	Dim sLine As String = Trim(Right(sST, i + 2))
	Logger.Error("Error at Line:  " &amp;amp; sLine &amp;amp; vbCrLf &amp;amp; oEx.Message)
End Sub&lt;/LI-CODE&gt;
&lt;P&gt;But, what I often use instead of that custom Sub routine in many places is a single Logger line of code on the Catch side, like the following example:&lt;/P&gt;
&lt;LI-CODE lang="general"&gt;Try
	'try to do something that might fail here
Catch oEx As Exception
	Logger.Error(oEx.Message &amp;amp; vbCrLf &amp;amp; oEx.StackTrace)
End Try&lt;/LI-CODE&gt;
&lt;P&gt;That writes both the error &lt;A href="https://learn.microsoft.com/en-us/dotnet/api/system.exception.message?view=net-7.0" target="_blank" rel="noopener"&gt;Message&lt;/A&gt; and its StackTrace to the iLogic Logger for me in one Error entry, so I have plenty of info on it, and the StackTrace already contains the error line number.&amp;nbsp; Quicker to type in, but takes up more room in the Logger screen later, so there is a trade off.&lt;/P&gt;</description>
      <pubDate>Tue, 08 Aug 2023 15:12:08 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-forum/to-retrieve-line-number-in-the-code/m-p/12157146#M87431</guid>
      <dc:creator>WCrihfield</dc:creator>
      <dc:date>2023-08-08T15:12:08Z</dc:date>
    </item>
    <item>
      <title>Re: To retrieve Line number in the Code</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-forum/to-retrieve-line-number-in-the-code/m-p/12157202#M87432</link>
      <description>&lt;P&gt;Actually, not that I am looking at it again, I see now that my routine also still has a limitation that I had not noticed.&amp;nbsp; Most of my rules are not more than 100 lines, because I like to divide my codes up into smaller bites, so I did not notice that the Error line would be cut off after the second digit.&amp;nbsp; I entered a ton of empty lines of code in a test rule just now to test it.&amp;nbsp; So, I changed a couple of those lines of code a bit to fix that limitation.&amp;nbsp; This code simply captures the text at the right end of the StackTrace that is just after the ".vb:line " text, using the overall length of the StackTrace, then subtracting the length of that text I am searching for (minus 1).&amp;nbsp; Now it is picking up all characters in the line number.&lt;/P&gt;
&lt;LI-CODE lang="general"&gt;Sub LogError(oEx As Exception)
	Dim sST As String = oEx.StackTrace
	Dim i As Integer = InStr(sST, ".vb:line ")
	Dim sLine As String = Trim(Right(sST, Len(sST) -(i + 8)))
	Logger.Error("Error at Line:  " &amp;amp; sLine &amp;amp; vbCrLf &amp;amp; oEx.Message)
End Sub&lt;/LI-CODE&gt;</description>
      <pubDate>Tue, 08 Aug 2023 15:30:32 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-forum/to-retrieve-line-number-in-the-code/m-p/12157202#M87432</guid>
      <dc:creator>WCrihfield</dc:creator>
      <dc:date>2023-08-08T15:30:32Z</dc:date>
    </item>
    <item>
      <title>Re: To retrieve Line number in the Code</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-forum/to-retrieve-line-number-in-the-code/m-p/12157230#M87433</link>
      <description>&lt;P&gt;&lt;span class="lia-unicode-emoji" title=":grinning_face_with_sweat:"&gt;😅&lt;/span&gt;&amp;nbsp;Haha...Sorry to keep posting, but there are soooo many ways to do String manipulations that there could probably be a dozen different ways to lay out a routine like this, but here is the shortest version yet.&amp;nbsp; Just another variation to review/test out.&lt;/P&gt;
&lt;LI-CODE lang="general"&gt;Sub LogError(oEx As Exception)
	Dim sLine As String = Trim(Split(oEx.StackTrace, ".vb:line ").Last)
	Logger.Error("Error at Line:  " &amp;amp; sLine &amp;amp; vbCrLf &amp;amp; oEx.Message)
End Sub&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 08 Aug 2023 15:43:35 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-forum/to-retrieve-line-number-in-the-code/m-p/12157230#M87433</guid>
      <dc:creator>WCrihfield</dc:creator>
      <dc:date>2023-08-08T15:43:35Z</dc:date>
    </item>
    <item>
      <title>Re: To retrieve Line number in the Code</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-forum/to-retrieve-line-number-in-the-code/m-p/12889329#M87434</link>
      <description>&lt;P&gt;I came across this post and implemented adding the line number to a message in the log so I know where to look when troubleshooting.&amp;nbsp; My only issue is that I'm having to subtract 9 from the line number to get the actual line where the error occurs.&amp;nbsp; Is there some hidden lines that I'm not aware of?&amp;nbsp; Has anyone else seen this?&lt;/P&gt;</description>
      <pubDate>Wed, 10 Jul 2024 15:05:09 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-forum/to-retrieve-line-number-in-the-code/m-p/12889329#M87434</guid>
      <dc:creator>andrewiv</dc:creator>
      <dc:date>2024-07-10T15:05:09Z</dc:date>
    </item>
    <item>
      <title>Re: To retrieve Line number in the Code</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-forum/to-retrieve-line-number-in-the-code/m-p/12889383#M87435</link>
      <description>&lt;P&gt;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/242037"&gt;@andrewiv&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;edit: oh wait, sorry I just noticed I already posted this in the past in&lt;A href="https://forums.autodesk.com/t5/inventor-programming-ilogic/to-retrieve-line-number-in-the-code/m-p/12156609#M156142" target="_blank" rel="noopener"&gt; post 8&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRIKE&gt;See slide from an&amp;nbsp;&lt;A href="https://www.autodesk.com/autodesk-university/class/iLogic-25-Tips-and-Tricks-Boost-Octane-your-Inventor-Automation-2022" target="_blank" rel="noopener"&gt;AU 2022 presentation&amp;nbsp;&lt;/A&gt;I did in the past. This is typically how I try to handle this.&lt;/STRIKE&gt;&lt;/P&gt;
&lt;P&gt;&lt;STRIKE&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Curtis_Waguespack_0-1720624876048.png" style="width: 300px;"&gt;&lt;img src="https://forums.autodesk.com/t5/image/serverpage/image-id/1385228i6E93140C1AAB1342/image-size/small?v=v2&amp;amp;px=200" role="button" title="Curtis_Waguespack_0-1720624876048.png" alt="Curtis_Waguespack_0-1720624876048.png" /&gt;&lt;/span&gt;&lt;/STRIKE&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 10 Jul 2024 15:26:47 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-forum/to-retrieve-line-number-in-the-code/m-p/12889383#M87435</guid>
      <dc:creator>Curtis_W</dc:creator>
      <dc:date>2024-07-10T15:26:47Z</dc:date>
    </item>
    <item>
      <title>Re: To retrieve Line number in the Code</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-forum/to-retrieve-line-number-in-the-code/m-p/12889423#M87436</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/242037"&gt;@andrewiv&lt;/a&gt;.&amp;nbsp; That's interesting and odd.&amp;nbsp; Which version/year of Inventor are you using?&amp;nbsp; If an error happens before Line 9, of what you see in the rule editor window, does it still report Line (# + 9)?&amp;nbsp; Yes, there is definitely more code involved in iLogic rules than what we see within our iLogic rule editor user interface area, but the other stuff should not be included in that Line number count.&amp;nbsp; However, sometimes we do get two different Line numbers being reported within our &lt;A href="https://learn.microsoft.com/en-us/dotnet/api/system.exception.stacktrace" target="_blank" rel="noopener"&gt;Exception.StackTrace&lt;/A&gt; text, and when that happens, it is usually the first instance within that message that is the relevant one, while the second one seems to be sort of like what line it was on within a temp file that got made for the rule.&amp;nbsp; This may be an issue that would require a much more robust block of code to weed out, but maybe not.&amp;nbsp; In my last example code above, I am using the '&lt;A href="https://learn.microsoft.com/en-us/dotnet/api/system.linq.enumerable.last" target="_blank" rel="noopener"&gt;Last&lt;/A&gt;' property of the Array of Strings that resulted from using '&lt;A href="https://learn.microsoft.com/en-us/dotnet/api/system.string.split" target="_blank" rel="noopener"&gt;Split&lt;/A&gt;' method on the &lt;A href="https://learn.microsoft.com/en-us/dotnet/api/system.exception.stacktrace" target="_blank" rel="noopener"&gt;StackTrace&lt;/A&gt; message.&amp;nbsp; You could try replacing that with '&lt;A href="https://learn.microsoft.com/en-us/dotnet/api/system.linq.enumerable.first" target="_blank" rel="noopener"&gt;First&lt;/A&gt;' property instead.&lt;/P&gt;
&lt;P&gt;I do not really use this reporting system all the time, and have not revisited it since looking at this post the last time.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Edit:&lt;/P&gt;
&lt;P&gt;I just did some quick local testing with a couple simple internal and external iLogic rules I just typed up, with no filtering of the StackTrace message contents.&amp;nbsp; It is 'only' including the Line # where the error happened within the 'temp' file, instead of from the local rule or native external rule file.&amp;nbsp; I am using Inventor Pro 2024.3 right now.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Now I'm thinking that maybe something changed either in the iLogic add-in, or in Inventor itself, but not sure.&amp;nbsp; The Line # being reported was about 2 or more lines below where it should have been.&amp;nbsp; So, as additional research, I followed the path of that temp file, and opened it to take a look at what is going on.&lt;/P&gt;
&lt;P&gt;This is the text of the internal (saved within the document) test iLogic rule:&lt;/P&gt;
&lt;LI-CODE lang="general"&gt;Sub Main
	Dim sStr As String = "123 in"
	Dim iInt As Integer = 456
	Dim oResult As Double
	Try
		oResult = sStr + iInt
	Catch oEx As System.Exception
		Logger.Error(vbCrLf &amp;amp; oEx.StackTrace)
	End Try
End Sub&lt;/LI-CODE&gt;
&lt;P&gt;And here is what was in the temp file shown within the StackTrace of the Exception it threw:&lt;/P&gt;
&lt;LI-CODE lang="general"&gt;
Public Partial Class ThisRule ''**iLogic system**
Public Sub Main() Implements IRuleInterface.Main ''**iLogic system**
	Dim sStr As String = "123 in"
	Dim iInt As Integer = 456
	Dim oResult As Double
	Try
		oResult = sStr + iInt
	Catch oEx As System.Exception
		Logger.Error(vbCrLf &amp;amp; oEx.StackTrace)
	End Try
End Sub


End Class ''**iLogic system**
&lt;/LI-CODE&gt;
&lt;P&gt;It has an empty starting line, and empty final line (cut-of in code window above).&amp;nbsp; It includes the Partial Class line, and the End Class Lines, which are normally hidden from view.&amp;nbsp; It adds the 'Public' access level specifier and Implements statement for one of the other iLogic Interfaces.&amp;nbsp; But it does not include any of the other 'hidden' code, such as the other portion of this Partial Class, and supporting references, imports, and such.&lt;/P&gt;
&lt;P&gt;Not sure why both the internal rule, and the external rule test examples I tried, with different types of errors, were both only reporting the error line of the temp file, and not the 'native' rule text Line number.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 10 Jul 2024 16:12:41 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-forum/to-retrieve-line-number-in-the-code/m-p/12889423#M87436</guid>
      <dc:creator>WCrihfield</dc:creator>
      <dc:date>2024-07-10T16:12:41Z</dc:date>
    </item>
    <item>
      <title>Re: To retrieve Line number in the Code</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-forum/to-retrieve-line-number-in-the-code/m-p/12889543#M87437</link>
      <description>&lt;P&gt;I'm on 2024.&amp;nbsp; If an error happens on line 1 it reports 10.&amp;nbsp; As I'm writing this I tested with a new file.&amp;nbsp; On this file it is only adding 7 to the line number.&amp;nbsp; Here is a pic of my code and the log.&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="andrewiv_0-1720628438006.png" style="width: 600px;"&gt;&lt;img src="https://forums.autodesk.com/t5/image/serverpage/image-id/1385261iE0D894E484D4B211/image-size/medium?v=v2&amp;amp;px=400" role="button" title="andrewiv_0-1720628438006.png" alt="andrewiv_0-1720628438006.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If I change it to the first property of the array this is the log.&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="andrewiv_1-1720628564833.png" style="width: 600px;"&gt;&lt;img src="https://forums.autodesk.com/t5/image/serverpage/image-id/1385262i4A23C9A2715D418C/image-size/medium?v=v2&amp;amp;px=400" role="button" title="andrewiv_1-1720628564833.png" alt="andrewiv_1-1720628564833.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 10 Jul 2024 16:22:54 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-forum/to-retrieve-line-number-in-the-code/m-p/12889543#M87437</guid>
      <dc:creator>andrewiv</dc:creator>
      <dc:date>2024-07-10T16:22:54Z</dc:date>
    </item>
    <item>
      <title>Re: To retrieve Line number in the Code</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-forum/to-retrieve-line-number-in-the-code/m-p/12889550#M87438</link>
      <description>&lt;P&gt;I copied and pasted your code from post 8 and this is the log I get.&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="andrewiv_0-1720628698490.png" style="width: 600px;"&gt;&lt;img src="https://forums.autodesk.com/t5/image/serverpage/image-id/1385263i818873EBF2797777/image-size/medium?v=v2&amp;amp;px=400" role="button" title="andrewiv_0-1720628698490.png" alt="andrewiv_0-1720628698490.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;It should say error at line 4.&amp;nbsp; I'm not sure what's going on, but I can account for it by just intentionally casing an error and then adjusting the log message to subtract the right amount to get the known line number.&lt;/P&gt;</description>
      <pubDate>Wed, 10 Jul 2024 16:28:55 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-forum/to-retrieve-line-number-in-the-code/m-p/12889550#M87438</guid>
      <dc:creator>andrewiv</dc:creator>
      <dc:date>2024-07-10T16:28:55Z</dc:date>
    </item>
    <item>
      <title>Re: To retrieve Line number in the Code</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-forum/to-retrieve-line-number-in-the-code/m-p/12889603#M87439</link>
      <description>&lt;P&gt;In that case, it looks like mine is acting similar to yours right now.&amp;nbsp; When I only log the whole StackTrace of the Exception, without the message, and without filtering anything out, it is pointing out the error that happened within the temp file located in the following temp folder:&lt;/P&gt;
&lt;P&gt;C:\Users\&amp;lt;username&amp;gt;\AppData\Local\Temp\iLogic Rules\&lt;/P&gt;
&lt;P&gt;...which always seems to have additional lines of code in it than what we are seeing in our rule editor.&lt;/P&gt;
&lt;P&gt;And it looks like maybe that temp file could have a somewhat random number of additional lines in it, making the 'offset' not that stable.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Maybe we should tag&amp;nbsp;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/537534"&gt;@MjDeck&lt;/a&gt;&amp;nbsp;on this topic.&lt;/P&gt;
&lt;P&gt;Has this error reporting process been changed in any recent releases / updates of Inventor?&lt;/P&gt;
&lt;P&gt;If so, is there a better way to Log the accurate Line number where the error occurred, based on the local/native rule text, rather than this temp file?&lt;/P&gt;
&lt;P&gt;It seems like if I do not use the Try...Catch...End Try block of code, and just allow the normal error window to pop-up, it is showing the correct Line number where the error happened.&amp;nbsp; Maybe we should be using a more native resource/tool for obtaining the accurate Line number of the error, using something like:&lt;/P&gt;
&lt;LI-CODE lang="general"&gt;Dim oErrorLine As Integer
Dim oiLogicELog As ExceptionsLog = iLogicVb.Automation.RuleExceptionsLog
If oiLogicELog.Count &amp;gt; 0 Then
	Dim oExs As IEnumerable = oiLogicELog.Exceptions
	If oExs IsNot Nothing Then
		For Each oEx As ExceptionLogEntry In oExs
			If oEx.Context = ExceptionContext.RuleRunning Then
				oErrorLine = oEx.LineNumber
			End If
		Next oEx
	End If
End If&lt;/LI-CODE&gt;</description>
      <pubDate>Wed, 10 Jul 2024 16:52:55 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-forum/to-retrieve-line-number-in-the-code/m-p/12889603#M87439</guid>
      <dc:creator>WCrihfield</dc:creator>
      <dc:date>2024-07-10T16:52:55Z</dc:date>
    </item>
    <item>
      <title>Re: To retrieve Line number in the Code</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-forum/to-retrieve-line-number-in-the-code/m-p/12889858#M87440</link>
      <description>&lt;P&gt;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/7812054"&gt;@WCrihfield&lt;/a&gt;&amp;nbsp;- as you found, if you allow the standard error dialog to pop up (instead of using a Try...Catch block) then you will see the correct line number. Internally, iLogic calculates the offset required. The way this offset calculation is done depends on the rule contents, and it has changed from release to release.&lt;BR /&gt;&lt;BR /&gt;So the line number in the exception message refers to the temporary file. That's what the .NET runtime sees. It doesn't see the original rule.&lt;BR /&gt;At this time, I would recommend opening the temporary file (instead of the original rule) to find the line. You could do that manually. Possibly you could automate it.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Maybe in a future release we can provide an iLogic API function to map a line number from the temporary file to the original rule. This would use the method that's currently being used by both the standard error dialog and the RuleExceptionsLog. (You can't use the&amp;nbsp;RuleExceptionsLog as is, because if you catch the exception yourself it won't go into the log.)&lt;/P&gt;</description>
      <pubDate>Wed, 10 Jul 2024 18:59:36 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-forum/to-retrieve-line-number-in-the-code/m-p/12889858#M87440</guid>
      <dc:creator>MjDeck</dc:creator>
      <dc:date>2024-07-10T18:59:36Z</dc:date>
    </item>
    <item>
      <title>Re: To retrieve Line number in the Code</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-forum/to-retrieve-line-number-in-the-code/m-p/12889887#M87441</link>
      <description>&lt;P&gt;Thanks for the explanation.&amp;nbsp; &lt;STRIKE&gt;It makes sense now, that when I'm using a try catch block the temp file starts immediately after the Try statement, so that is the number I have to subtract to get the correct line.&lt;/STRIKE&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Nevermind, I looked at the temp file and it just depends on the calls I'm making with my rule and what it has to import for each rule.&amp;nbsp; I'll just make sure I test my rules with a forced error so I know the number I need to use to get the same line as the rule editor.&lt;/P&gt;</description>
      <pubDate>Wed, 10 Jul 2024 19:18:01 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-forum/to-retrieve-line-number-in-the-code/m-p/12889887#M87441</guid>
      <dc:creator>andrewiv</dc:creator>
      <dc:date>2024-07-10T19:18:01Z</dc:date>
    </item>
  </channel>
</rss>

