TextBox1 is an object that has many properties. You want the text property which is the actual text string. Something like this:
TextBox1.Text = <put your string here>
It may require a more full reference to the text box in the form..
Me.Controls("TextBox1").Text = <put your string here>
This is for VBA.
Have you set Length, Width and Height as double?
Also could you share full macro to debug?
I've attached the macro. I hope this helps make sense of the issue.
Try running the Macro on an empty part, or adding a feature, specifically an extrude to a part after the macro has been run. This is where the error occurs.
No, The userform was part of the original macro that I downloaded. I removed the code to display the userform as it is not necessary for what I'm using this for.
I get error on empty part which I think is OK. If I add a feature and run macro, it works OK. And then if I add another feature, the macro run in the background updating the values and move the macro feature to last of the tree.
I need to be able to insert the macro feature into my part template and have it stay. Currently it errors out and then removes the feature from the tree. I am not having your luck with adding features, specifically extrudes.
Have all the variables in that line (Length, Width, Height) been initialized?
One helpful step when posting questions is to provide context (the entire Sub/Function that you are working on or even the entire macro if it isn't proprietary).
Dim TextBox1 As String
Dim Length As String
Dim Width As String
Dim Height As String
Length = ""
Width = ""
Height = ""
TextBox1 = Length & " x " & Height & " x " & Width
Default properties for objects are for amateurs and idiots. Try not to be either.
It looks like you are misunderstanding the use of textboxes (and variable types in general) in VBA. In brief, the error you are seeing is happening because you have defined "TextBox1" as an object, and you are attempting to assign a string value to that variable. In VBA, object assignments are done using "Set". Because the format (and assignment type) aren't correct here, it is looking for something that doesn't exist - hence the missing variable error.
In a bit more detail, there are two main issues that are collaborating here:
The first is what I mentioned above. In this case, you want to use something like the following format:
Dim TextBox1 as Object
Set TextBox1 = UserForm1.TextBox1
TextBox1.Text = Length & " x " & Height & " x " & Width
You have done the first part of this near the top of mainTestMacro2(), but all of the following lines try to directly assign a string to "TextBox1" instead of "TextBox1.Text". For example, line 344 is currently:
TextBox1 = TextBox1 + "" + Chr(13)
Correct the error, and it should look like:
TextBox1.Text = TextBox1.Text + "" + Chr(13)
Note that in the variable declaration, you could also use "Dim TextBox1 as TextBox" here, since that appears to be the variable type that you are working with. Predefining the object type like this gives VBA the ability to pull up a dropdown menu of useful properties and methods as you type, to make sure that you are making the correct calls. It isn't strictly necessary, but it can be helpful.
The second problem is an issue with the flow of your macro. Near the top of the Sub, you have a conditional that sends the program to the "semMassa" section if swModel.GetMassProperties is empty. This is fine in and of itself, but then that section tries to make a reference to the TextBox1 variable. This is a problem, because that variable was never set! Remember, you skipped over the part where you set up the TextBox1,2,3 objects. Right now, this part of your code looks like this:
<If model mass properties are empty, go to semMassa>
<Assign TextBox1,2,3 variables to UserForm1 objects>
<semMassa: Do some stuff, then make a call to TextBox1 variable>
So, you're skipping all the stuff in the middle. When the program gets to the reference to TextBox1 in semMassa, you haven't assigned any object to that variable - so it is empty, and you get the object not set error. You can fix this by assigning the TextBox object variables earlier in the code (before that conditional).
And finally, I just noticed that your semMassa section looks like it was intended to be run only sometimes, not every time the macro is run. Right now, you will get to that section of the code no matter what because your macro doesn't have an exit prior to the "semMassa" section start. If you don't want it to run, you will want to put an "Exit Sub" after the last line of code above that section, but before the section name.
Hope this helps! Let me know if it doesn't make sense.