How do you do complex select case structures?

NeoTechni

Well-Known Member
Licensed User
Longtime User
I'd like to do ranges without using if/then, ie: (VB6)

temp is a float
B4X:
select case temp
          case 0
          case is > 2 and < 4
end select
 

Ricky D

Well-Known Member
Licensed User
Longtime User
Only way I know is to use if then.... Else if blocks

Regards, Ricky
 
Upvote 0

Ricky D

Well-Known Member
Licensed User
Longtime User
Example
B4X:
If var=0 Then 
Else If var> 2 AND var<4 Then
Else If var>10 Then
Else
'do something not covered
End If

Regards, Ricky
 
Upvote 0

kickaha

Well-Known Member
Licensed User
Longtime User
I'd like to do ranges without using if/then, ie: (VB6)

temp is a float
B4X:
select case temp
          case 0
          case is > 2 and < 4
end select

Why not do something like:
B4X:
select case temp
          case 0
               code here for 0
          case <=2
                no code here so select is exited for <= 2
          case  < 4
               code here for > 2 and < 4
end select
 
Upvote 0

NeoTechni

Well-Known Member
Licensed User
Longtime User
Why not do something like:
B4X:
select case temp
          case 0
               code here for 0
          case <=2
                no code here so select is exited for <= 2
          case  < 4
               code here for > 2 and < 4
end select

That won't do it, I need to know how to do multiple cases within a single case line.
 
Upvote 0

Mahares

Expert
Licensed User
Longtime User
Since you cannot do < (less than) and > (bigger than) in SELECT CASES, if you are looking for ranges, I hope this is what you are looking for. If not, please provide more details:


B4X:
   Dim tmp As Float
   Dim Itmp As Int   
   Itmp=Floor(tmp)

   Select  Itmp
         Case 0   'handles 0 to 0.99
            Msgbox("Case  0 to 0.99. Your number is: " & tmp ,"")
            'Do this
         Case 1   'handles 1 to 1.99   
             Msgbox(" Case 1 to 1.99. Your number is " & tmp ,"")
             'Do the other
         Case 2,3     'handles 2 to 3.99   
              Msgbox("Case 2 to 3.99. Your number is " & tmp ,"")
               'Do that
         Case Else     'handles 4 and above
            Msgbox("Case 4 and above. Your number is: " & tmp ,"")
            'Do something else
   End Select
 
Upvote 0
Top