Reply

Small question, check if property exists.

When i check all the properties of the part, i want to check if there is a value, and when this value doesn't exists I want to add the custom property. 

 

The macro does a check every time in a loop, then the next row and so on. So how can I put a overall check? Something like "If after the last loop still "value" = nothing then add .....

 

You would really help me with this.

 

 For i As Integer = 1 To Main.SEDocumentPropertySets.Count
            Main.SEDocumentProperties = Main.SEDocumentPropertySets.Item(i)

            For j As Integer = 1 To Main.SEDocumentProperties.Count
                Main.SEDocumentProperty = Main.SEDocumentProperties.Item(j)
 If Main.SEDocumentProperty.Name = "Aantal" Then
                    Main.SEDocumentProperty.Value = TextBox_Aantal.Text
End If

      Next
        Next
3 REPLIES

Re: Small question, check if property exists.

[ Edited ]

Hi,

 

you could use

 

If String.IsNullOrEmpty(Cstr(Main.SEDocumentProperty.Value)) then
   ' Add value

EndIf

to check for a non empty value.

If you want check whether your property exists at all you could use

 

...
Dim propertyFound as Boolean = False

' Outer loop for PropertySets
For ...
   ...
   ' Inner loop for Properties
   For ...
      If Main.SEDocumentProperty.Name = "Aantal" Then
         propertyFound = True
         ' Set its value
         ...
    Next
Next

If Not propertyFound then
   ' Add property
   ...
EndIf

 

 

Kind regards,
Wolfgang Kunert - www.wksyspro.de

Re: Small question, check if property exists.

 

It doesn't work. This code adds the value when it exists but does not create it of gives the messagebox...

        For i As Integer = 1 To Main.SEDocumentPropertySets.Count
            Main.SEDocumentProperties = Main.SEDocumentPropertySets.Item(i)

            For j As Integer = 1 To Main.SEDocumentProperties.Count
                Main.SEDocumentProperty = Main.SEDocumentProperties.Item(j)

                If Main.SEDocumentProperty.Name = "Subject" Then
                    Main.SEDocumentProperty.Value = ComboBox_Ondertitel.Text
                End If

                If Main.SEDocumentProperty.Name = "Klant" Then
                    Main.SEDocumentProperty.Value = ComboBox_Klant.Text
                End If

                If String.IsNullOrEmpty("aantal") Then
                    'MsgBox("test")
                    'Form_InfoNoApplication.Show()
                    Main.SEDocumentProperties.Add("Aantal", TextBox_Aantal.Text)
                                 Else
                    If Main.SEDocumentProperty.Name = "Aantal" Then
                        Main.SEDocumentProperty.Value = TextBox_Aantal.Text
                    End If
                End If

            Next
        Next

Re: Small question, check if property exists.

Dim propAantalFound as Boolean = False
        
For i As Integer = 1 To Main.SEDocumentPropertySets.Count
            Main.SEDocumentProperties = Main.SEDocumentPropertySets.Item(i)

            For j As Integer = 1 To Main.SEDocumentProperties.Count
                Main.SEDocumentProperty = Main.SEDocumentProperties.Item(j)

                If Main.SEDocumentProperty.Name = "Subject" Then
                    Main.SEDocumentProperty.Value = ComboBox_Ondertitel.Text
                End If

                If Main.SEDocumentProperty.Name = "Klant" Then
                    Main.SEDocumentProperty.Value = ComboBox_Klant.Text
                End If

                 If Main.SEDocumentProperty.Name = "Aantal" Then
                        propAantalFound = True
                        Main.SEDocumentProperty.Value = TextBox_Aantal.Text
                    End If
                End If

            Next
        Next

If Not propAantalFound Then
   Main.SEDocumentPropertySets("Custom").Add("Aantal", TextBox_Aantal.Text)
EndIf
Kind regards,
Wolfgang Kunert - www.wksyspro.de