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

Do all custom iProperties require a string output?

I'm trying to set up a code where I can update an iProperty based on inputs.  I modified the example code to update iProperties.  The sub would be used with texts, bools, and numbers.  I set the input as a variant but get errors if I pass anything other than a variant or string.  What's the rules on iProps?

Public Sub CalliProp()

Dim docCurr As Document
Set docCurr = ThisApplication.ActiveDocument

Dim dblTest As Double
dblTest = 3.22222

Call UpdateCustomiProp(docCurr, "Woohah", dblTest)

End Sub
Public Sub UpdateCustomiProp(docDoc As Document, strPropTitle As String, varValue As Variant)
       
    ' Get the custom property set.
    Dim psCustom As PropertySet
    Set psCustom = docDoc.PropertySets.Item("Inventor User Defined Properties")
        
    Dim propCurrent As Property
    Set propCurrent = psCustom.Item(strPropTitle)
    
    If Err.Number <> 0 Then
        ' Failed to get the property, which means it doesn't exist
        ' so we'll create it.
        Call psCustom.Add(varValue, strPropTitle)
    Else
        ' Got the property so update the value.
        propCurrent.Value = varValue
    End If

End Sub
omartin
in reply to: JBEDsol

Custom iProps can be what ever type that is available when you go and add one manually.

You can use the object type instead of variant to make it generic.

Keep in mind the iproperty type will change depending on what type of value you assign ex: assigning "123" and 123 will change the iproperty type automatically between string and number.

Was my reply Helpful ? send a Kudos or accept as solution
JBEDsol
in reply to: omartin

I found out if I use byval in front of the variant designation for my sub it works