<?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 Basic VB question in Inventor Programming - iLogic, Macros, AddIns &amp; Apprentice</title>
    <link>https://forums.autodesk.com/t5/inventor-programming-ilogic/basic-vb-question/m-p/9402962#M107380</link>
    <description>&lt;P&gt;This is probably something very basic, but I would like to know the reason why the following does not work:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;Sub Main()
    Dim oDoc as Inventor.Document = ThisApplication.ActiveDocument
    Dim sDispName as String = oDoc.DisplayName
    sDispName = "doc123"
End Sub&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Whereas the following works fine:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;Sub Main()
    Dim oDoc as Inventor.Document = ThisApplication.ActiveDocument
    oDoc.DisplayName = "doc123"
End Sub&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;I'm guessing it has something to do with not referencing the object or something, but would like to be sure. If this is the case, when would I need to make sure I set a reference to an object with the various properties in the API? Is it only if the type of the property is not a built-in VB data type?&lt;/P&gt;</description>
    <pubDate>Thu, 26 Mar 2020 21:09:04 GMT</pubDate>
    <dc:creator>SometimesInventorMakesMeAngry</dc:creator>
    <dc:date>2020-03-26T21:09:04Z</dc:date>
    <item>
      <title>Basic VB question</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-ilogic/basic-vb-question/m-p/9402962#M107380</link>
      <description>&lt;P&gt;This is probably something very basic, but I would like to know the reason why the following does not work:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;Sub Main()
    Dim oDoc as Inventor.Document = ThisApplication.ActiveDocument
    Dim sDispName as String = oDoc.DisplayName
    sDispName = "doc123"
End Sub&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Whereas the following works fine:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;Sub Main()
    Dim oDoc as Inventor.Document = ThisApplication.ActiveDocument
    oDoc.DisplayName = "doc123"
End Sub&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;I'm guessing it has something to do with not referencing the object or something, but would like to be sure. If this is the case, when would I need to make sure I set a reference to an object with the various properties in the API? Is it only if the type of the property is not a built-in VB data type?&lt;/P&gt;</description>
      <pubDate>Thu, 26 Mar 2020 21:09:04 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-ilogic/basic-vb-question/m-p/9402962#M107380</guid>
      <dc:creator>SometimesInventorMakesMeAngry</dc:creator>
      <dc:date>2020-03-26T21:09:04Z</dc:date>
    </item>
    <item>
      <title>Re: Basic VB question</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-ilogic/basic-vb-question/m-p/9403600#M107387</link>
      <description>&lt;P&gt;Hi &lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/6881685"&gt;@SometimesInventorMakesMeAngry&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;In your first example you're simply changing which string your variable stores, while in the second example you're changing the value of a property in an object.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Consider your variable oDoc for example:&lt;/P&gt;&lt;P&gt;Dim oDoc As Inventor.Document = ThisApplication.ActiveDocument&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If you'd change that to another document object like oDoc = someotherdocument it would not change which document is active in Inventor. It would only change which document is stored in your variable oDoc.&lt;/P&gt;&lt;P&gt;In other words, that does not change the property ActiveDocument in the application object.&lt;/P&gt;&lt;P&gt;Same thing &lt;img class="lia-deferred-image lia-image-emoji" src="https://forums.autodesk.com/html/@B4D44A73814D7FC0D950DEDFACB97081/emoticons/1f642.png" alt=":slightly_smiling_face:" title=":slightly_smiling_face:" /&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Both your examples work, they're just doing different things.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 27 Mar 2020 07:16:17 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-ilogic/basic-vb-question/m-p/9403600#M107387</guid>
      <dc:creator>JhoelForshav</dc:creator>
      <dc:date>2020-03-27T07:16:17Z</dc:date>
    </item>
    <item>
      <title>Re: Basic VB question</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-ilogic/basic-vb-question/m-p/9404373#M107410</link>
      <description>&lt;P&gt;That makes sense. Is there a way to store&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;ThisApplication.ActiveDocument.DisplayName&lt;/LI-CODE&gt;&lt;P&gt;all in one variable so I can change the active document's display name like?&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;DocDisplayName = "doc123"&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 27 Mar 2020 13:12:19 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-ilogic/basic-vb-question/m-p/9404373#M107410</guid>
      <dc:creator>SometimesInventorMakesMeAngry</dc:creator>
      <dc:date>2020-03-27T13:12:19Z</dc:date>
    </item>
    <item>
      <title>Re: Basic VB question</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-ilogic/basic-vb-question/m-p/9404557#M107414</link>
      <description>&lt;P&gt;I really don't think so...&lt;/P&gt;&lt;P&gt;Hopefully someone here will correct me if im wrong.&lt;/P&gt;</description>
      <pubDate>Fri, 27 Mar 2020 14:25:52 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-ilogic/basic-vb-question/m-p/9404557#M107414</guid>
      <dc:creator>JhoelForshav</dc:creator>
      <dc:date>2020-03-27T14:25:52Z</dc:date>
    </item>
    <item>
      <title>Re: Basic VB question</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-ilogic/basic-vb-question/m-p/9404571#M107415</link>
      <description>&lt;P&gt;Thank you!&lt;/P&gt;</description>
      <pubDate>Fri, 27 Mar 2020 14:31:56 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-ilogic/basic-vb-question/m-p/9404571#M107415</guid>
      <dc:creator>SometimesInventorMakesMeAngry</dc:creator>
      <dc:date>2020-03-27T14:31:56Z</dc:date>
    </item>
    <item>
      <title>Re: Basic VB question</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-ilogic/basic-vb-question/m-p/9404700#M107422</link>
      <description>&lt;P&gt;To add to Jhoel's comments, what you're really dealing with here is the difference between &lt;A href="https://docs.microsoft.com/en-us/dotnet/visual-basic/programming-guide/language-features/data-types/value-types-and-reference-types" target="_blank" rel="noopener"&gt;Value types and Reference types&lt;/A&gt;. To quote the Microsoft documentation (emphasis mine):&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;BLOCKQUOTE&gt;Variables of reference types store &lt;U&gt;references&lt;/U&gt; to their data (objects), while variables of value types &lt;U&gt;directly contain&lt;/U&gt; their data. With reference types, two variables can reference the same object; therefore, operations on one variable can affect the object referenced by the other variable. With value types, each variable has its own copy of the data, and it is not possible for operations on one variable to affect the other&lt;/BLOCKQUOTE&gt;&lt;P&gt;Strings are one of the Value types. Other Value types include all numeric types, Boolean, Char, and Date. Because the &lt;FONT face="courier new,courier"&gt;oDoc.DisplayName&lt;/FONT&gt; property returns a string, it's not possible to store the DisplayName property as a variable to be modified directly later. When you say &lt;FONT face="courier new,courier" color="#0000FF"&gt;Dim sDispName as String = oDoc.DisplayName&lt;/FONT&gt;, all this does is take the data that&amp;nbsp;&lt;FONT face="courier new,courier"&gt;oDoc.DisplayName&lt;/FONT&gt; returns and store a&amp;nbsp;&lt;STRONG&gt;copy&lt;/STRONG&gt; of it in sDispName. There's not actually any connection (reference) between sDispName and &lt;FONT face="courier new,courier"&gt;oDoc.DisplayName&lt;/FONT&gt;.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This is in contrast to something like &lt;FONT face="courier new,courier"&gt;oDoc.PropertySets&lt;/FONT&gt;, which returns a PropertySets object, which is a &lt;STRONG&gt;reference&lt;/STRONG&gt; type. So you can say &lt;FONT face="courier new,courier" color="#0000FF"&gt;Dim propSets As PropertySets = oDoc.PropertySets&lt;/FONT&gt;, and then later say &lt;FONT face="courier new,courier"&gt;propSets.Add("name")&lt;/FONT&gt; and it will actually add to oDoc's property sets, because propSets&amp;nbsp;&lt;STRONG&gt;references&lt;/STRONG&gt; (points to) the same object as &lt;FONT face="courier new,courier"&gt;oDoc.PropertySets&lt;/FONT&gt;.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;But in order to actually modify the value of a Value-type property of an object, you have to invoke the object itself, as you do here:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;Sub Main()
    Dim oDoc as Inventor.Document = ThisApplication.ActiveDocument
    oDoc.DisplayName = "doc123"
End Sub&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So that is going to be the most succinct way to modify the DisplayName if you need to do it multiple times.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;All that said, depending on what you're actually trying to do (I would assume this was just an example), there may be some tricks to make things more succinct, perhaps by writing a Function or even a custom Class. If you come across a real-life situation where it would be useful to have some kind of shortcut for setting the value of a value-type property, post it here and we'll see what we can come up with.&lt;/P&gt;</description>
      <pubDate>Fri, 27 Mar 2020 15:23:30 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-ilogic/basic-vb-question/m-p/9404700#M107422</guid>
      <dc:creator>DRoam</dc:creator>
      <dc:date>2020-03-27T15:23:30Z</dc:date>
    </item>
    <item>
      <title>Re: Basic VB question</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-ilogic/basic-vb-question/m-p/9499638#M110538</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;BLOCKQUOTE&gt;Variables of reference types store &lt;U&gt;references&lt;/U&gt; to their data (objects), while variables of value types &lt;U&gt;directly contain&lt;/U&gt; their data. With reference types, two variables can reference the same object; therefore, operations on one variable can affect the object referenced by the other variable. With value types, each variable has its own copy of the data, and it is not possible for operations on one variable to affect the other&lt;/BLOCKQUOTE&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;That makes perfect sense. Thanks!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This must be related to why you can say ByRef or ByVal when declaring a function.&lt;/P&gt;</description>
      <pubDate>Thu, 07 May 2020 16:21:25 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-ilogic/basic-vb-question/m-p/9499638#M110538</guid>
      <dc:creator>SometimesInventorMakesMeAngry</dc:creator>
      <dc:date>2020-05-07T16:21:25Z</dc:date>
    </item>
  </channel>
</rss>

