case ist & else case is executing and not others.

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • kmssunil
    New Member
    • Nov 2013
    • 1

    case ist & else case is executing and not others.

    The case ist & else case is executing but not others

    Code:
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
            Dim marks As Integer 
            marks = CInt(TextBox1.Text)
            Select Case marks
                Case Is > 35
                    MsgBox("number is greater than 35")
    
                Case Is > 50
                    MsgBox("number is greater than 50")
                Case Is > 65
                    MsgBox("number is greater than 65")
                Case Is > 75
                    MsgBox("number is greater than 75")
                Case Else
                    MsgBox("wrong entery")
            End Select
        End Sub
    Last edited by Frinavale; Dec 2 '13, 03:43 PM. Reason: Added code tags. Added the problem to the body of the thread so that the code posted makes sense.
  • Luuk
    Recognized Expert Top Contributor
    • Mar 2012
    • 1043

    #2
    Code:
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    Dim marks As Integer
    marks = CInt(TextBox1.Text)
    Select Case marks
    Case Is > 35
    MsgBox("number is greater than 35")
    hmm, above you tested if its >35, what will be the answer to the next question?
    Code:
    Case Is > 50
    MsgBox("number is greater than 50")
    Case Is > 65
    MsgBox("number is greater than 65")
    Case Is > 75
    MsgBox("number is greater than 75")
    Case Else
    MsgBox("wrong entery")
    End Select
    End Sub

    I sure love the possibility of these '[CODE]'-tags....

    Comment

    • Frinavale
      Recognized Expert Expert
      • Oct 2006
      • 9749

      #3
      Consider changing the order of your select cases so that the largest value is the first case and the smallest value is the last one.
      Code:
      Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
              Dim marks As Integer 
              marks = CInt(TextBox1.Text)
              Select Case marks
                  Case Is > 75
                      MsgBox("number is greater than 75")               
                   Case Is > 65
                      MsgBox("number is greater than 65")
                  Case Is > 50
                      MsgBox("number is greater than 50")
                  Case Is > 35
                      MsgBox("number is greater than 35")
                  Case Else
                      MsgBox("wrong entery")
              End Select
          End Sub

      Comment

      Working...