Check Values in If Then

DCooper

Member
Licensed User
Longtime User
I'm a newbie here and can't figure out how to make this work, and I have tried other variations to no avail...
If TotalA = 0 To 0.304 Then
Msgbox("2","Recommended Size")
Else If TotalA = 0.305 to .500 Then
Msgbox("3","Recommended Size")
End If

Thanks!
 

JonPM

Well-Known Member
Licensed User
Longtime User
B4X:
If TotalA >= 0 AND TotalA <= 0.304 Then
Msgbox("2","Recommended Size")
Else If TotalA >= 0.305 AND TotalA <= .500 Then
Msgbox("3","Recommended Size")
End If
End If
 
Upvote 0

timwil

Active Member
Licensed User
Longtime User
How about this:

B4X:
   If (Total >=0) And (Total<= 0.304) Then
      .....do whatever

   Else If (Total >=0.305) And (Total<= 0.5) Then
      .....do whatever

   Else
      .....do whatever

   End If
 
Upvote 0

klaus

Expert
Licensed User
Longtime User
I would change it to this:
B4X:
   If (TotalA >= 0) And (TotalA <= 0.304) Then
      .....do whatever

   Else If (TotalA > 0.304) And (TotalA <= 0.5) Then
      .....do whatever

   Else
      .....do whatever

   End If
Because if the value of Total = 0.3045 then it would have been in the Else section.

Best regards
 
Upvote 0

DCooper

Member
Licensed User
Longtime User
I would change it to this:
B4X:
   If (TotalA >= 0) And (TotalA <= 0.304) Then
      .....do whatever

   Else If (TotalA > 0.304) And (TotalA <= 0.5) Then
      .....do whatever

   Else
      .....do whatever

   End If
Because if the value of Total = 0.3045 then it would have been in the Else section.

Best regards

Thank you so much! It worked like a charm.
 
Upvote 0

kickaha

Well-Known Member
Licensed User
Longtime User
why not remove TotalA > 0.304 from the Else If, as we know that it is if it got to that line.
B4X:
   If (TotalA >= 0) And (TotalA <= 0.304) Then
      .....do whatever

   Else If TotalA <= 0.5 Then
      .....do whatever

   Else
      .....do whatever

   End If
 
Last edited:
Upvote 0

tremara1

Active Member
Licensed User
Longtime User
not covering the range

I believe values in the first evaluation will be included in the second evaluation, it does not limit the overall evaluation to the range required.
 
Upvote 0

kickaha

Well-Known Member
Licensed User
Longtime User
I believe values in the first evaluation will be included in the second evaluation, it does not limit the overall evaluation to the range required.

No, if TotalA <= 0.304 then the second evaluation is never processed, so no need to check there if it is >0.304, as it must be (the clue is in the word ELSE). :p

If you need confirmation, try running this code
B4X:
TotalA = 0.2

If (TotalA >= 0) AND (TotalA <= 0.304) Then      
   Log (">0 <=0.304")   
   Else If TotalA <= 0.5 Then  
      Log (">0.304 <=0.5")
   Else     
      Log (">0.5")
End If
and alter TotalA, you will find only one of the logs can trigger, never two.
 
Upvote 0
Top