"PropName(P).Text" should be replaced by "PropName(P)": If PropName(P) <> "" Then
Thanks for the example.
In this case it's shown only one property and one text box.
As I mentioned in my first post, I am trying to combine multiple properties with textboxes
I can add code to each property as shown below, but is it possible to shorten the number of lines by combining the numbers
If Description.Text <> "" Then Prop = Model.AddCustomInfo3("", Propname(2), swCustomInfoText, "") Model.CustomInfo(Propname(2)) = Description.Text End If If Number.Text <> "" Then Prop = Model.AddConfigInfo3("", Propname(3), swConfigInfoText, "") Model.ConfigInfo(Propname(3)) = Number.Text End If
No, but you can reduce lines by feeding in the property value on the same line where you're creating it:
If Description.Text <> "" Then
Model.AddCustomInfo3("", Propname(2), swCustomInfoText, Description.Text)
Note that your code will fail unless you fix "configinfo" to "custominfo".
Also, (if I recall correctly) AddCustomInfo3 will fail if the property referenced already exists.
Dim i As Integer
Dim Propname(3) As String
Propname(0) = "Description": Propname(1) = "Number": Propname(2) = "DrawnBy"
Dim PropVal(3) As String
PropVal(0) = Description.Text: PropVal(1) = Number.Text: PropVal(2) = DrawnBy.Text
For i = 0 To 3
Prop = Model.AddConfigInfo3("", Propname(i), swConfigInfoText, "")
Model.ConfigInfo(Propname(i)) = PropVal(i)
Thanks to Josh & Viktor,
I will try to modify as you mentioned and correct the errors
Let me do the testing tomorrow
The reason your macro did not work because you placed action code in "main" procedure. Whereas, "main" had to call only form. Should be something like this.
Public swApp As Object
Public Model As Object
Public Counter As Integer
Set swApp = Application.SldWorks
Set Model = swApp.ActiveDoc
Counter = 0
All loops and actions should be called after user presses buttons in your user form in the code behind this user form.
Hope this helps.
Thanks for the solution.
I learned an important point today, when using user form