If comparision doesn't work

If comparision doesn't work

Guido.LangeTuchscherer
Enthusiast Enthusiast
577 Views
6 Replies
Message 1 of 7

If comparision doesn't work

Guido.LangeTuchscherer
Enthusiast
Enthusiast

Hello there,

 

I am trying to compare a parameter to the extent in X-Direction. The Values fit, but the statement doesn't do anything. So I guess I am mixing types?

What are theses Strings, Integer?

 

If Parameter("G_L") = Round(Measure.ExtentsLength, 0) Then
MsgBox("Länge identisch")
End If

 

0 Likes
Accepted solutions (1)
578 Views
6 Replies
Replies (6)
Message 2 of 7

JhoelForshav
Mentor
Mentor

@Guido.LangeTuchscherer 

You should be able to compare that way... Are you sure they're the same?

Sometimes float values can be a bit difficult to compare. For example 100 could be interpreted as 100.000000000001 in the system. Therefore I'd recommend using DoubleForEquals to compare doubles.

See example below. First i make sure that they're in fact the same. Then I make the comparison:

MsgBox("ExtentsLength: " & Round(Measure.ExtentsLength, 0) & vbCrLf & _
"G_L: " & Parameter("G_L"))
If DoubleForEquals.IsEqual(Parameter("G_L"), Round(Measure.ExtentsLength, 0)) Then MsgBox("They're the same")
Message 3 of 7

Guido.LangeTuchscherer
Enthusiast
Enthusiast

@JhoelForshav 

Great thanks, now I just need the not equal equivalent or less than, how do you do those?

0 Likes
Message 4 of 7

JhoelForshav
Mentor
Mentor
Accepted solution

Something like this maybe? 🙂

Select Case True
Case DoubleForEquals.IsEqual(Parameter("G_L"), Round(Measure.ExtentsLength, 0))
MsgBox("Equal")
Case Parameter("G_L") > Round(Measure.ExtentsLength, 0)
MsgBox("G_L is greater than ExtentsLength")
Case Parameter("G_L") < Round(Measure.ExtentsLength, 0)
MsgBox("ExtentsLength is greater than G_L")
End Select
Message 5 of 7

Guido.LangeTuchscherer
Enthusiast
Enthusiast

@JhoelForshav 

Your solution works I just wonder why the if statements behave a bit strange:

 

aLength = Round(Measure.ExtentsLength, 0)
oLength = Parameter("G_L")
'Works			
If DoubleForEquals.IsEqual(oLength, Round(Measure.ExtentsLength, 0)) Then MsgBox("They're the same") ' iProperties.Value("Custom", "Abmessungen") = "L = " & oLength & " mm"
'Does not work Else If oLength < Round(Measure.ExtentsLength, 0) Then MsgBox("They're not the same") End If

If oLength = aLength Then 'works
' iProperties.Value("Custom", "Abmessungen") = "L = " & oLength & " mm"
MsgBox("Länge identisch / Same length")
Else If oLength < aLength Then 'doesn't work
' iProperties.Value("Custom", "Abmessungen") = "L = " & Round(Measure.ExtentsLength, 0) & " mm"
MsgBox("Länge nicht identisch / different length")
End If

 

0 Likes
Message 6 of 7

JhoelForshav
Mentor
Mentor

@Guido.LangeTuchscherer 

Your If-statements work fine for me... Are you sure the ExtentsLength isn't smaller than G_L when you try it? Because you have nothing handling that so that wouldn't return any messagebox at all...

0 Likes
Message 7 of 7

Guido.LangeTuchscherer
Enthusiast
Enthusiast

@JhoelForshav 

 

You are right i turned the operator < the wrong way, always test both ways to be sure....😉

0 Likes