Reply

How to test for Custom Prop?

[ Edited ]

 

All,

 

I am trying to test to see if a custom property named "Total Cost" exsist.

 

I am currently using this method:

 

terr = 0

       For Each objprops In objpropsets

            If objprops.Name = "Custom" Then

                ' checks to see if Total Cost property already exist

                For Each objprop In objprops

                    If objprop.Name = "Total Cost" Then

                        terr = 0

                        Exit For

                    Else

                        terr = 1

                    End If

                Next objprop

                If terr = 1 Then

                    'DO THIS...

                    MessageBox.Show("No Total Found so ...DO THIS...")

                End If

            End If

        Next objprops

 

I wanted to use something more direct.  I've tried the following to no avil:

 

If Not (objpropsets.Item("Custom").Item("Total Cost") Is Nothing) Then

            MessageBox.Show("IS NOTHING Total Cost Does Exsist")

        Else

            MessageBox.Show("IS NOTHING Total Cost DOES NOT Exsist")

        End If

 

What is the bast way to test for a custom property???

 

Thank you much for the help!

 

~Matt

 

Posted by: Matt Johnson
Post date: 8/1/2008 9:38:32 AM

2 REPLIES

RE: How to test for Custom Prop?

[ Edited ]

Klaus Dahlenburg replied in the Solid Edge forums. Here is his response:

 

Matt,

 

the coding will raise the error 'Subscript out of Range', so be warned.

In VB6 I would code this way:

 

Dim oProps As Object

Dim oProp As Object

Set oProps = mDraft.Properties.Item("Custom")

On Error Resume Next

Set oProp = oProps.Item("Total Cost")

' alternate way

' Set oProp = mDraft.Properties.Item("Custom").Item("Total Cost")

If not (oProp is nothing) Then

MsgBox ("Total Cost Does Exsist")

Else

MsgBox ("Total Cost DOES NOT Exsist")

End If

err.clear

....

....

Set oProp = Nothing

Set oProps = Nothing

 

When there is no need for the object "Total Cost" the If Not (... is Nothing) might

be used as well

 

Klaus

 

Posted by: Jason Newell
Post date: 8/3/2008 7:29:35 PM

RE: How to test for Custom Prop?

[ Edited ]

Thanks Jason!

 

Posted by: Matt Johnson
Post date: 8/4/2008 4:05:18 AM