Comparing with numbers help

pluton

Active Member
Licensed User
Longtime User
Hi

I just begining in android and wonder how will i make some compare with numbers.

ex: I have number in

Dim number As Double
number = 25.9
Dim tekst As String


If number < 19.1 Then
tekst = "Short"
End If

If number > 19.1 AND number < 25.8 Then
tekst = "Tall"
End If

If number > 25.9 AND number < 27.3 Then
tekst = "High"
End If

'.... and some more numbers to compare
'How will I compare this numbers and get result in string tekst


:sign0085:
 

rbsoft

Active Member
Licensed User
Longtime User
B4X:
If number > 25.9 AND number < 27.3 Then
tekst = "High"
End If

You should change this to

B4X:
If [B]number >= 25.9[/B] AND number < 27.3 Then
tekst = "High"
End If

Otherwise the value 25.9 will never be evaluated. Alternatively you also could use

B4X:
If number > 25.8 AND number < 27.3 Then...

This then also would include 25.9.

The same applies for the other comparisons. You are leaving gaps.
 
Last edited:
Upvote 0

pluton

Active Member
Licensed User
Longtime User
Thanks

Will try this and post result :sign0060:

Edit:
This code do the job. Thanks again :D

If number >= 25.9 AND number < 27.3 Then
tekst = "High"
End If
 
Last edited:
Upvote 0

klaus

Expert
Licensed User
Longtime User
I would suggest you following code:
B4X:
If number <= 19.1 Then 
  tekst = "Short"
Else If number <= 25.9 Then
  tekst = "Tall"
Else If number <=27.3 Then
  tekst = "High"
Else
  tekst = "XXL"
End If

In the code above, when one condition is satisfied the others are no more tested. In your example all If/Then tests will be done, even if the first one is satisfied.

Be careful,
number >= 25.9 is not the same as number > 25.8

What about 25.85, it will not be in the same category if you use one or the other comparison.

Best regards.
 
Upvote 0
Top