<?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: The dreaded - Object reference not set to an instance of an object in Inventor Programming - iLogic, Macros, AddIns &amp; Apprentice</title>
    <link>https://forums.autodesk.com/t5/inventor-programming-ilogic/the-dreaded-object-reference-not-set-to-an-instance-of-an-object/m-p/12142119#M155898</link>
    <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/8494199"&gt;@darren.lees&lt;/a&gt;.&amp;nbsp; When you declare an Array type variable, it can be tricky.&amp;nbsp; You either have to not specify the size/length of the array, then set all of its contents at that line of code, or you must specify its size/length, then not specify its contents at that line of code, then fill in its contents later, being careful not to go pas that pre-set size.&amp;nbsp; It is often easier to create a 'New List(Of String)' when you do not know how many entries you may need to put into it.&amp;nbsp; Then just use its Add or AddRange method to add its contents.&amp;nbsp; Its size/length does not matter, plus a List is super easy to 'Sort' later.&amp;nbsp; If you need to specify size, you may be able to use 'oPartList.PartsListRows.Count - 1', because Arrays are zero based (zero is its first entry index).&lt;/P&gt;</description>
    <pubDate>Tue, 01 Aug 2023 19:10:46 GMT</pubDate>
    <dc:creator>WCrihfield</dc:creator>
    <dc:date>2023-08-01T19:10:46Z</dc:date>
    <item>
      <title>The dreaded - Object reference not set to an instance of an object</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-ilogic/the-dreaded-object-reference-not-set-to-an-instance-of-an-object/m-p/12142101#M155897</link>
      <description>&lt;P&gt;Hi All,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have another, hopefully, eaay problem.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I wish to interrogate a parts list on a drawing.&amp;nbsp; Something I've done in the past.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;However, this time I'm tring to populate an array with each of the values in the REVISION column.&lt;/P&gt;&lt;P&gt;I'll then figure out how to find the highest value character in the array and do some magic in the drawing based on that.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;My dilema is, when I try to add a value to the array inside a FOR LOOP, I get the dreaded "&lt;STRONG&gt;Object reference not set to an instance of an object&lt;/STRONG&gt;" error and my limited knowledge of VB.NET can't sem to get past it.&amp;nbsp; It has to be an easy fix.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Code below.....&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="visual-basic"&gt;' Set a reference to the drawing document.
' This assumes a drawing document is active.
Dim oDrawDoc As DrawingDocument
oDrawDoc = ThisApplication.ActiveDocument

Dim oPartList As PartsList
oPartList = oDrawDoc.ActiveSheet.PartsLists.Item(1)

' Iterate through the contents of the parts list
Dim i As Long
Dim LetterArray() As String
For i = 1 To oPartList.PartsListRows.Count
	'look at only the REVISION column
	oCell = oPartList.PartsListRows.Item(i).Item("REVISION")
	
	'Test to see if we have the correct REVISION letter
	MessageBox.Show("Revision of item " &amp;amp; i &amp;amp; " is " &amp;amp; oCell.Value, "Revs")

	'Populate the array with the REVISION letter
	LetterArray(i) = oCell.Value
	'PRODUCES THIS - Object reference not set to an instance of an object
	'PLEASE HELP!!!   I don't ask for much.  I'm a good man.....really!!!
	'I pay my bills and taxes......etc!!
Next
	&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Please help!!&lt;BR /&gt;&lt;BR /&gt;This was easier when we just used BASIC as a language.&amp;nbsp; Who thought it was a good idea to invent different computer languages??&amp;nbsp; Sheesh!!!&amp;nbsp;&lt;img class="lia-deferred-image lia-image-emoji" src="https://forums.autodesk.com/html/@108A86EAEBDCD23B42C9DA513E42C4E6/emoticons/1f923.png" alt=":rolling_on_the_floor_laughing:" title=":rolling_on_the_floor_laughing:" /&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;</description>
      <pubDate>Tue, 01 Aug 2023 19:00:02 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-ilogic/the-dreaded-object-reference-not-set-to-an-instance-of-an-object/m-p/12142101#M155897</guid>
      <dc:creator>darren.lees</dc:creator>
      <dc:date>2023-08-01T19:00:02Z</dc:date>
    </item>
    <item>
      <title>Re: The dreaded - Object reference not set to an instance of an object</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-ilogic/the-dreaded-object-reference-not-set-to-an-instance-of-an-object/m-p/12142119#M155898</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/8494199"&gt;@darren.lees&lt;/a&gt;.&amp;nbsp; When you declare an Array type variable, it can be tricky.&amp;nbsp; You either have to not specify the size/length of the array, then set all of its contents at that line of code, or you must specify its size/length, then not specify its contents at that line of code, then fill in its contents later, being careful not to go pas that pre-set size.&amp;nbsp; It is often easier to create a 'New List(Of String)' when you do not know how many entries you may need to put into it.&amp;nbsp; Then just use its Add or AddRange method to add its contents.&amp;nbsp; Its size/length does not matter, plus a List is super easy to 'Sort' later.&amp;nbsp; If you need to specify size, you may be able to use 'oPartList.PartsListRows.Count - 1', because Arrays are zero based (zero is its first entry index).&lt;/P&gt;</description>
      <pubDate>Tue, 01 Aug 2023 19:10:46 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-ilogic/the-dreaded-object-reference-not-set-to-an-instance-of-an-object/m-p/12142119#M155898</guid>
      <dc:creator>WCrihfield</dc:creator>
      <dc:date>2023-08-01T19:10:46Z</dc:date>
    </item>
    <item>
      <title>Re: The dreaded - Object reference not set to an instance of an object</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-ilogic/the-dreaded-object-reference-not-set-to-an-instance-of-an-object/m-p/12142239#M155899</link>
      <description>&lt;P&gt;Hi &lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/7812054"&gt;@WCrihfield&lt;/a&gt;,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;We meet again.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'll give your suggestion a go tomorrow and see what happens.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks for now.&lt;/P&gt;</description>
      <pubDate>Tue, 01 Aug 2023 19:56:40 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-ilogic/the-dreaded-object-reference-not-set-to-an-instance-of-an-object/m-p/12142239#M155899</guid>
      <dc:creator>dleesuk</dc:creator>
      <dc:date>2023-08-01T19:56:40Z</dc:date>
    </item>
    <item>
      <title>Re: The dreaded - Object reference not set to an instance of an object</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-ilogic/the-dreaded-object-reference-not-set-to-an-instance-of-an-object/m-p/12142461#M155901</link>
      <description>&lt;P&gt;Or, when the String is declared, it is "null".&lt;/P&gt;&lt;P&gt;A zero length String.&lt;/P&gt;&lt;P&gt;Hence&amp;nbsp;LetterArray(1) fail.&lt;/P&gt;&lt;P&gt;Try LetterArray = LetterArray +&amp;nbsp;oCell.Value.&lt;/P&gt;</description>
      <pubDate>Tue, 01 Aug 2023 21:25:38 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-ilogic/the-dreaded-object-reference-not-set-to-an-instance-of-an-object/m-p/12142461#M155901</guid>
      <dc:creator>Frederick_Law</dc:creator>
      <dc:date>2023-08-01T21:25:38Z</dc:date>
    </item>
    <item>
      <title>Re: The dreaded - Object reference not set to an instance of an object</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-ilogic/the-dreaded-object-reference-not-set-to-an-instance-of-an-object/m-p/12142645#M155904</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/993965"&gt;@dleesuk&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You can use something like this to find the largest rev letter.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I hope this helps.&lt;BR /&gt;Best of luck to you in all of your Inventor pursuits,&lt;BR /&gt;Curtis&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;SPAN&gt;Dim&lt;/SPAN&gt; &lt;SPAN&gt;oDrawDoc&lt;/SPAN&gt; &lt;SPAN&gt;As&lt;/SPAN&gt; &lt;SPAN&gt;DrawingDocument&lt;/SPAN&gt;
&lt;SPAN&gt;oDrawDoc&lt;/SPAN&gt; = &lt;SPAN&gt;ThisApplication&lt;/SPAN&gt;.&lt;SPAN&gt;ActiveDocument&lt;/SPAN&gt;

&lt;SPAN&gt;Dim&lt;/SPAN&gt; &lt;SPAN&gt;oPartList&lt;/SPAN&gt; &lt;SPAN&gt;As&lt;/SPAN&gt; &lt;SPAN&gt;PartsList&lt;/SPAN&gt;
&lt;SPAN&gt;oPartList&lt;/SPAN&gt; = &lt;SPAN&gt;oDrawDoc&lt;/SPAN&gt;.&lt;SPAN&gt;ActiveSheet&lt;/SPAN&gt;.&lt;SPAN&gt;PartsLists&lt;/SPAN&gt;.&lt;SPAN&gt;Item&lt;/SPAN&gt;(1)

&lt;SPAN&gt;oMax&lt;/SPAN&gt; = &lt;SPAN&gt;"A"&lt;/SPAN&gt;
&lt;SPAN&gt;oRowMax&lt;/SPAN&gt; = 1

&lt;SPAN&gt;' Iterate through the contents of the parts list&lt;/SPAN&gt;
&lt;SPAN&gt;Dim&lt;/SPAN&gt; &lt;SPAN&gt;i&lt;/SPAN&gt; &lt;SPAN&gt;As&lt;/SPAN&gt; &lt;SPAN&gt;Long&lt;/SPAN&gt;
&lt;SPAN&gt;For&lt;/SPAN&gt; &lt;SPAN&gt;i&lt;/SPAN&gt; = 1 &lt;SPAN&gt;To&lt;/SPAN&gt; &lt;SPAN&gt;oPartList&lt;/SPAN&gt;.&lt;SPAN&gt;PartsListRows&lt;/SPAN&gt;.&lt;SPAN&gt;Count&lt;/SPAN&gt;
	&lt;SPAN&gt;'look at only the REVISION column&lt;/SPAN&gt;
	&lt;SPAN&gt;oCell&lt;/SPAN&gt; = &lt;SPAN&gt;oPartList&lt;/SPAN&gt;.&lt;SPAN&gt;PartsListRows&lt;/SPAN&gt;.&lt;SPAN&gt;Item&lt;/SPAN&gt;(&lt;SPAN&gt;i&lt;/SPAN&gt;).&lt;SPAN&gt;Item&lt;/SPAN&gt;(&lt;SPAN&gt;"REVISION"&lt;/SPAN&gt;)

	&lt;SPAN&gt;Dim&lt;/SPAN&gt; &lt;SPAN&gt;letterarray&lt;/SPAN&gt; &lt;SPAN&gt;As&lt;/SPAN&gt; &lt;SPAN&gt;New&lt;/SPAN&gt; &lt;SPAN&gt;ArrayList&lt;/SPAN&gt;
	&lt;SPAN&gt;letterarray&lt;/SPAN&gt;.&lt;SPAN&gt;Add&lt;/SPAN&gt;(&lt;SPAN&gt;oCell&lt;/SPAN&gt;.&lt;SPAN&gt;Value&lt;/SPAN&gt;)
	&lt;SPAN&gt;letterarray&lt;/SPAN&gt;.&lt;SPAN&gt;Add&lt;/SPAN&gt;(&lt;SPAN&gt;oMax&lt;/SPAN&gt;)
	&lt;SPAN&gt;letterarray&lt;/SPAN&gt;.&lt;SPAN&gt;Sort&lt;/SPAN&gt;
	&lt;SPAN&gt;oMax&lt;/SPAN&gt; = &lt;SPAN&gt;letterarray&lt;/SPAN&gt;.&lt;SPAN&gt;Item&lt;/SPAN&gt;(1)

	&lt;SPAN&gt;If&lt;/SPAN&gt; &lt;SPAN&gt;oCell&lt;/SPAN&gt;.&lt;SPAN&gt;Value&lt;/SPAN&gt; = &lt;SPAN&gt;oMax&lt;/SPAN&gt; &lt;SPAN&gt;Then&lt;/SPAN&gt; &lt;SPAN&gt;oRowMax&lt;/SPAN&gt; = &lt;SPAN&gt;i&lt;/SPAN&gt;
&lt;SPAN&gt;Next&lt;/SPAN&gt;

&lt;SPAN&gt;MsgBox&lt;/SPAN&gt;(&lt;SPAN&gt;"Row "&lt;/SPAN&gt; &amp;amp; &lt;SPAN&gt;oRowMax&lt;/SPAN&gt; &amp;amp; &lt;SPAN&gt;" has the largest rev letter of "&lt;/SPAN&gt; &amp;amp; _
&lt;SPAN&gt;oPartList&lt;/SPAN&gt;.&lt;SPAN&gt;PartsListRows&lt;/SPAN&gt;.&lt;SPAN&gt;Item&lt;/SPAN&gt;(&lt;SPAN&gt;oRowMax&lt;/SPAN&gt;).&lt;SPAN&gt;Item&lt;/SPAN&gt;(&lt;SPAN&gt;"REVISION"&lt;/SPAN&gt;).&lt;SPAN&gt;Value&lt;/SPAN&gt;, , &lt;SPAN&gt;"iLogic"&lt;/SPAN&gt;)&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 01 Aug 2023 23:38:05 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-ilogic/the-dreaded-object-reference-not-set-to-an-instance-of-an-object/m-p/12142645#M155904</guid>
      <dc:creator>Curtis_Waguespack</dc:creator>
      <dc:date>2023-08-01T23:38:05Z</dc:date>
    </item>
    <item>
      <title>Re: The dreaded - Object reference not set to an instance of an object</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-ilogic/the-dreaded-object-reference-not-set-to-an-instance-of-an-object/m-p/12143239#M155909</link>
      <description>&lt;P&gt;Hi Curtis,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you for that.&amp;nbsp; It works very well!!&amp;nbsp; &amp;nbsp;A big shout out to&amp;nbsp;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/7812054"&gt;@WCrihfield&lt;/a&gt;&amp;nbsp;&amp;amp;&amp;nbsp;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/5289378"&gt;@Frederick_Law&lt;/a&gt;&amp;nbsp;also.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Now onto the 'magic' I spoke of earlier.&lt;/P&gt;</description>
      <pubDate>Wed, 02 Aug 2023 07:10:01 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-ilogic/the-dreaded-object-reference-not-set-to-an-instance-of-an-object/m-p/12143239#M155909</guid>
      <dc:creator>dleesuk</dc:creator>
      <dc:date>2023-08-02T07:10:01Z</dc:date>
    </item>
  </channel>
</rss>

