Announcements
Attention for Customers without Multi-Factor Authentication or Single Sign-On - OTP Verification rolls out April 2025. Read all about it here.

To add to Jhoel's comments, what you're really dealing with here is the difference between Value types and Reference types. To quote the Microsoft documentation (emphasis mine):

 

Variables of reference types store references to their data (objects), while variables of value types directly contain 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

Strings are one of the Value types. Other Value types include all numeric types, Boolean, Char, and Date. Because the oDoc.DisplayName property returns a string, it's not possible to store the DisplayName property as a variable to be modified directly later. When you say Dim sDispName as String = oDoc.DisplayName, all this does is take the data that oDoc.DisplayName returns and store a copy of it in sDispName. There's not actually any connection (reference) between sDispName and oDoc.DisplayName.

 

This is in contrast to something like oDoc.PropertySets, which returns a PropertySets object, which is a reference type. So you can say Dim propSets As PropertySets = oDoc.PropertySets, and then later say propSets.Add("name") and it will actually add to oDoc's property sets, because propSets references (points to) the same object as oDoc.PropertySets.

 

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:

 

 

Sub Main()
    Dim oDoc as Inventor.Document = ThisApplication.ActiveDocument
    oDoc.DisplayName = "doc123"
End Sub

 

 

So that is going to be the most succinct way to modify the DisplayName if you need to do it multiple times.

 

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.