Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
980 views
in Technique[技术] by (71.8m points)

vb.net - select case to check range of a decimal number

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 sure of the syntax. please help!

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
    Select Case aa
        Case 1 To 1.49
            MsgBox(1)
        Case 1.5 To 2
            MsgBox(2)
        Case Else
            MsgBox("was lower than 1 or higher than 2 or between 1.49 and 1.5")
    End Select

this(below) would go into case else

   Dim aa As Double = 1.499

this(below) will go into case 1 to 1.49

   Dim aa As Double = 1.4

this(below) will go into case 1.5 to 2

   Dim aa As Double = 1.78

other way of doing it: From here

    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

and maybe this too:

    Select Case true
        Case (value >= 0 andalso value <= 49.99)
            Debug.WriteLine("first group")
        Case (value >= 50 andalso value <= 99.99)
            Debug.WriteLine("second group")
        Case (value >= 100 andalso value <= 199.99)
            Debug.WriteLine("third group")
        Case Else
            Debug.WriteLine("fourth group")
    End Select

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...