<?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 LispFunction Test....CRASH in .NET Forum</title>
    <link>https://forums.autodesk.com/t5/net-forum/lispfunction-test-crash/m-p/2845998#M62751</link>
    <description>&lt;P&gt;Why does the following code crash AutoCAD with unhandled Exception.....please be gentle...&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Imports Autodesk.AutoCAD.Runtime&lt;BR /&gt;Imports Autodesk.AutoCAD.ApplicationServices&lt;BR /&gt;Imports Autodesk.AutoCAD.DatabaseServices&lt;BR /&gt;Imports Autodesk.AutoCAD.EditorInput&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Public Class jb&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;LispFunction("test")&amp;gt; _&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Public Function jbStart(ByVal testarray As ResultBuffer) As ResultBuffer&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Dim rbfResult As ResultBuffer&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Dim jbtestarray As Array&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 'jbtestarray = testarray.AsArray&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; jbtestarray(0) = 1&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; jbtestarray(1) = 2&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; jbtestarray(2) = 3&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Dim myarg As Double&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Dim myTypeVal As TypedValue&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Dim i As Integer = 0&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; While i &amp;lt; jbtestarray.Length&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; myTypeVal = jbtestarray.GetValue(i)&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; rbfResult = New ResultBuffer(New TypedValue(CInt(LispDataType.Double), myarg))&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; i = i + 1&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; End While&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Return rbfResult&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; End Function&lt;BR /&gt;End Class&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 07 Dec 2010 20:20:05 GMT</pubDate>
    <dc:creator>Anonymous</dc:creator>
    <dc:date>2010-12-07T20:20:05Z</dc:date>
    <item>
      <title>LispFunction Test....CRASH</title>
      <link>https://forums.autodesk.com/t5/net-forum/lispfunction-test-crash/m-p/2845998#M62751</link>
      <description>&lt;P&gt;Why does the following code crash AutoCAD with unhandled Exception.....please be gentle...&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Imports Autodesk.AutoCAD.Runtime&lt;BR /&gt;Imports Autodesk.AutoCAD.ApplicationServices&lt;BR /&gt;Imports Autodesk.AutoCAD.DatabaseServices&lt;BR /&gt;Imports Autodesk.AutoCAD.EditorInput&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Public Class jb&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;LispFunction("test")&amp;gt; _&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Public Function jbStart(ByVal testarray As ResultBuffer) As ResultBuffer&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Dim rbfResult As ResultBuffer&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Dim jbtestarray As Array&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 'jbtestarray = testarray.AsArray&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; jbtestarray(0) = 1&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; jbtestarray(1) = 2&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; jbtestarray(2) = 3&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Dim myarg As Double&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Dim myTypeVal As TypedValue&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Dim i As Integer = 0&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; While i &amp;lt; jbtestarray.Length&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; myTypeVal = jbtestarray.GetValue(i)&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; rbfResult = New ResultBuffer(New TypedValue(CInt(LispDataType.Double), myarg))&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; i = i + 1&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; End While&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Return rbfResult&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; End Function&lt;BR /&gt;End Class&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 07 Dec 2010 20:20:05 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/lispfunction-test-crash/m-p/2845998#M62751</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2010-12-07T20:20:05Z</dc:date>
    </item>
    <item>
      <title>Re: LispFunction Test....CRASH</title>
      <link>https://forums.autodesk.com/t5/net-forum/lispfunction-test-crash/m-p/2846200#M62752</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;EM&gt;jerry.bryant wrote:&lt;BR /&gt;&lt;/EM&gt;&lt;P&gt;&lt;EM&gt;Why does the following code crash AutoCAD with unhandled Exception.....please be gentle...&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;That is really two questions...&amp;nbsp; Why does it crash, and why is it an unhandled exception.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;It is an Unhandled exception, because you don't have any error handling code.&lt;/P&gt;&lt;P&gt;Put a Try/Catch block in it, and the exception text that arises will probably tell you what is happening.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;That said, from what I see, you should be getting a warning from Visual Studio, that jbtestarray has been used before it has been assigned a value, on this line&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;jbtestarray(0) = 1&lt;/P&gt;This is because you created a variable to hold an array, but that variable does not yet contain an instance of an array.&lt;/BLOCKQUOTE&gt;&lt;P&gt;&amp;nbsp; Your code would also fail here:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;myTypeVal = jbtestarray.GetValue(i)&lt;/P&gt;&lt;P&gt;because you can not set a variable expecting a TypedValue equal to a variable containing a Double.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;and here: (well, not really fail as in error, but fail as in not give the desired result)&lt;/P&gt;&lt;P&gt;rbfResult = New ResultBuffer(New TypedValue(CInt(LispDataType.Double), myarg))&lt;/P&gt;&lt;P&gt;because MyArg has not been assigned a value, so it will always be zero, and because since you are assigning rbfResult to a New ResultBuffer each time, the returned result would only contain the last value.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here's a guess at what you are actually trying to do.&lt;/P&gt;&lt;PRE&gt;&amp;lt;LispFunction("test")&amp;gt; _
  Public Function jbStart(ByVal testarray As ResultBuffer) As ResultBuffer
	Dim rbfResult As New ResultBuffer
	Try
		Dim jbtestarray() As TypedValue = testarray.AsArray	'this would fail if no arguments are passed
		Dim myarg As Double
		Dim myTypeVal As TypedValue
		Dim i As Integer = 0
		While i &amp;lt; jbtestarray.Length  'I would use a for/next loop here
			myTypeVal = jbtestarray(i)
			myarg = myTypeVal.Value
			rbfResult.Add(New TypedValue(CInt(LispDataType.Double), myarg))
			i = i + 1
		End While
		Return rbfResult
	Catch ex As Exception
		MsgBox(ex.Message &amp;amp; vbLf &amp;amp; ex.StackTrace)
		Return Nothing
	End Try
End Function&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;which is essentially the same thing as having just one line of code&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Return testarray&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;But I assume you are trying to figure out how to make use of this data for another purpose, so enjoy.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;and, to prevent the code from failing if no arguments are passed (see comment in code), you should add a check at the beginning (very first line) that says 'if testarray is Nothing then Return Nothing'.&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, 07 Dec 2010 22:21:57 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/lispfunction-test-crash/m-p/2846200#M62752</guid>
      <dc:creator>chiefbraincloud</dc:creator>
      <dc:date>2010-12-07T22:21:57Z</dc:date>
    </item>
    <item>
      <title>Re: LispFunction Test....CRASH</title>
      <link>https://forums.autodesk.com/t5/net-forum/lispfunction-test-crash/m-p/2846278#M62753</link>
      <description>&lt;P&gt;Thx,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This is the part that I don't understand....your reply..&lt;/P&gt;&lt;P&gt;&lt;EM&gt;"That said, from what I see, you should be getting a warning from Visual Studio &lt;STRONG&gt;(YES I AM GETTING THIS WARNING),&lt;/STRONG&gt; that jbtestarray has been used before it has been assigned a value, on this line&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;&amp;nbsp;&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;jbtestarray(0) = 1&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;This is because you created a variable to hold an array, but that variable does not yet contain an instance of an array.&lt;SPAN&gt;&amp;nbsp;"&lt;/SPAN&gt;&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Ok...I have..&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Dim jbtestarray As Array&lt;/P&gt;&lt;P&gt;jbtestarray(0) = 1&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;How do I "create an instance" of the array before filling it?....I think I am havng a mental block on this one....&lt;/P&gt;&lt;P&gt;Thx again&lt;/P&gt;</description>
      <pubDate>Tue, 07 Dec 2010 23:04:27 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/lispfunction-test-crash/m-p/2846278#M62753</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2010-12-07T23:04:27Z</dc:date>
    </item>
    <item>
      <title>Re: LispFunction Test....CRASH</title>
      <link>https://forums.autodesk.com/t5/net-forum/lispfunction-test-crash/m-p/2846394#M62754</link>
      <description>&lt;P&gt;There are a couple of ways...&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Dim jbtestarray As Array basically makes an array that has no size or type.&lt;/P&gt;&lt;P&gt;One way to fix that, staying with the code you have, is to use the Shared CreateInstance method of the Array Class, like this:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Dim jbtestarray as Array = Array.CreateInstance(GetType(Double), 2)&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The return value of the CreateInstance method is an Instance of an Array with Type Double and Max index 2.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;In most cases, I prefer a different approach, which gives you a Typed array with no set size in the declaration, like I did in my example code.&lt;/P&gt;&lt;P&gt;Dim jbtestarray() As&amp;nbsp;TypedValue&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If you were to follow that line of code with another which said jbtestarray(0) = 1, you would still get the same error, because although the Array is already Typed, it has no Size.&amp;nbsp; At this point the array either needs to be given a size manually using 'ReDim jbtestarray(2)', or you can set it equal to the return value of a function that returns an array, in which case the variable you created becomes a reference to the returned array instance, which was sized by the function you called, and which is&amp;nbsp;what I did in my code by Dim jbtestarray() as TypedValue = testarray.AsArray&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This is of course most useful when you don't know the size of the array at design time.&amp;nbsp; And also to prevent errors that would be caused by someone passing the wrong number of arguments to your LispFunction.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;You can also Type and Size the array at the same time as declaring it, like:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Dim jbtestarray(2) as Double&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If you then Follow that with a line that says jbtestarray(0) = 1, there will be no problem, because the array has already been sized and typed.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Hope that helps.&lt;/P&gt;</description>
      <pubDate>Wed, 08 Dec 2010 00:26:31 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/lispfunction-test-crash/m-p/2846394#M62754</guid>
      <dc:creator>chiefbraincloud</dc:creator>
      <dc:date>2010-12-08T00:26:31Z</dc:date>
    </item>
  </channel>
</rss>

