Compare

Compare

Anonymous
Not applicable
411 Views
2 Replies
Message 1 of 3

Compare

Anonymous
Not applicable

Hello 

i want ask if i load parameter as variable in vba can i compare Textbox value and parameter value ? 

my program still show that this condition is false. 

pdp parameter is 10 mm and TextBox1 is 5

Dim pdl As Parameter
Set pdl= parametre.Item("pdl")

 

If TextBox1.Value > pdl.Value  Then
MsgBox "Warning detection"
Else
pdp.Expression = TextBox1.Text
End If

Accepted solutions (2)
412 Views
2 Replies
Replies (2)
Message 2 of 3

FINET_Laurent
Advisor
Advisor
Accepted solution

Morning,

 

I'd post this question on the Inventor customization forum category, which fit better with your question.

 

Maybe convert the TextBox1 input to Double or Integer  variable before comparing?


Regards,

FINET L.

If this post solved your question, please kindly mark it as "Solution"

If this post helped out in any way to solve your question, please drop a "Like"

@LinkedIn     @JohnCockerill

0 Likes
Message 3 of 3

WCrihfield
Mentor
Mentor
Accepted solution

I see that when you Set the value of the "pdl" variable, you are using a variable named "parametre".  Is that variable spelled correctly?  Has that variable been defined as the Parameters, or ModelParameters, or UserParameters collection of a document before this point in the code?

If the value of TextBox1 is 5 and the value of the parameter named "pdl" is 10, then yes [5 > 10] will equal False, because 5 is not 'larger than' 10.  However, in your situation the value of the TextBox1 (if it is defined as a MSForms.TextBox) is most likely being understood as a Variant, and the value of the Parameter is most likely being understood as Variant, and since a Variant can hold nearly any type of data, they likely aren't being compared correctly.  So, what you may have to do before you can properly compare the two values is convert the value of both the TextBox1 and the Parameter to a Double, before attempting to compare them (similar to what @FINET_Laurent  suggested).

   Here's an example of how to do this:  (I've added some code and variables to define the objects involved, but you can just delete those if they are already defined within your code.)

Dim oPDoc As PartDocument
Set oPDoc = ThisApplication.ActiveDocument
Dim oPDef As PartComponentDefinition
Set oPDef = oPDoc.ComponentDefinition
Dim oParams As Parameters
Set oParams = oPDef.Parameters

Dim pdl As Parameter
Set pdl = oParams.Item("pdl")

Dim TextBox1 As MSForms.TextBox
'Set TextBox1 =

If CDbl(TextBox1.Value) > CDbl(pdl.Value) Then
MsgBox "Warning detection"
Else
pdp.Expression = TextBox1.Text
End If

You'll notice that I am encapsulating both sides of the comparison using a simple conversion code, so they will both be understood as Double Type data, which is what the < & > operators are meant to compare.

 

If this solved your problem, or answered your question, please click ACCEPT SOLUTION.
Or, if this helped you, please click 'LIKE' 👍.

If you have time, please... Vote For My IDEAS 💡and Explore My CONTRIBUTIONS

Inventor 2020 Help | Inventor Forum | Inventor Customization Forum | Inventor Ideas Forum

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes