By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,952 Members | 1,616 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,952 IT Pros & Developers. It's quick & easy.

case ist & else case is executing and not others.

P: 1
The case ist & else case is executing but not others

Expand|Select|Wrap|Line Numbers
  1. Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
  2.         Dim marks As Integer 
  3.         marks = CInt(TextBox1.Text)
  4.         Select Case marks
  5.             Case Is > 35
  6.                 MsgBox("number is greater than 35")
  7.  
  8.             Case Is > 50
  9.                 MsgBox("number is greater than 50")
  10.             Case Is > 65
  11.                 MsgBox("number is greater than 65")
  12.             Case Is > 75
  13.                 MsgBox("number is greater than 75")
  14.             Case Else
  15.                 MsgBox("wrong entery")
  16.         End Select
  17.     End Sub
Nov 25 '13 #1
Share this Question
Share on Google+
2 Replies


Expert 100+
P: 1,031
Expand|Select|Wrap|Line Numbers
  1. Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
  2. Dim marks As Integer
  3. marks = CInt(TextBox1.Text)
  4. Select Case marks
  5. Case Is > 35
  6. MsgBox("number is greater than 35")
  7.  
hmm, above you tested if its >35, what will be the answer to the next question?
Expand|Select|Wrap|Line Numbers
  1. Case Is > 50
  2. MsgBox("number is greater than 50")
  3. Case Is > 65
  4. MsgBox("number is greater than 65")
  5. Case Is > 75
  6. MsgBox("number is greater than 75")
  7. Case Else
  8. MsgBox("wrong entery")
  9. End Select
  10. End Sub 

I sure love the possibility of these '[code]'-tags....
Nov 25 '13 #2

Frinavale
Expert Mod 5K+
P: 9,731
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.
Expand|Select|Wrap|Line Numbers
  1. Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
  2.         Dim marks As Integer 
  3.         marks = CInt(TextBox1.Text)
  4.         Select Case marks
  5.             Case Is > 75
  6.                 MsgBox("number is greater than 75")               
  7.              Case Is > 65
  8.                 MsgBox("number is greater than 65")
  9.             Case Is > 50
  10.                 MsgBox("number is greater than 50")
  11.             Case Is > 35
  12.                 MsgBox("number is greater than 35")
  13.             Case Else
  14.                 MsgBox("wrong entery")
  15.         End Select
  16.     End Sub
Dec 2 '13 #3

Post your reply

Sign in to post your reply or Sign up for a free account.