select case to check range of a decimal number

后端 未结 9 596
抹茶落季
抹茶落季 2020-12-11 17:37

i need to check whether a demical is 0 through 49.99 or 50 through 99.99 or 100 through 199.99 or greater than 200. i am trying to do this with select case, but i am not sur

相关标签:
9条回答
  • 2020-12-11 18:12

    Why don't you try if/then/else? They are equivalent, and I am not sure if case statement in VBasic can handle non-integers values.

    0 讨论(0)
  • 2020-12-11 18:17
     Dim value As Double = 133.5
            Select Case value
                Case Is <= 49.99
                    Debug.WriteLine("first group")
                Case Is <= 99.99
                    Debug.WriteLine("second group")
                Case Is <= 199.99
                    Debug.WriteLine("third group")
                Case Else
                    Debug.WriteLine("fourth group")
            End Select
    

    Where do values as 49.992 fall in your question? Since you said 0-49.99 and then 50-99.99 anything between 49.99 and 50 where does it go? In my example above it would be included in one of the options so it is values between 0 and 49.99, values between 49.99 and 99.99, etc, etc.

    0 讨论(0)
  • 2020-12-11 18:19
    Dim range as Integer
    range = someInteger / 50
    'So, if range = 0 is 0-49.99, if it's 1 it's 50 to 99.99, etc
    
    0 讨论(0)
提交回复
热议问题