pluton Active Member Licensed User Longtime User Aug 20, 2011 #1 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:
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 Aug 20, 2011 #2 Code: If number > 25.9 AND number < 27.3 Then tekst = "High" End If You should change this to Code: 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 Code: 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: Aug 20, 2011 Upvote 0
Code: If number > 25.9 AND number < 27.3 Then tekst = "High" End If You should change this to Code: 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 Code: 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.
pluton Active Member Licensed User Longtime User Aug 20, 2011 #3 Thanks Will try this and post result :sign0060: Edit: This code do the job. Thanks again If number >= 25.9 AND number < 27.3 Then tekst = "High" End If Click to expand... Last edited: Aug 20, 2011 Upvote 0
Thanks Will try this and post result :sign0060: Edit: This code do the job. Thanks again If number >= 25.9 AND number < 27.3 Then tekst = "High" End If Click to expand...
klaus Expert Licensed User Longtime User Aug 20, 2011 #4 I would suggest you following code: Code: 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
I would suggest you following code: Code: 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.