rbulph Posted October 16, 2013 Posted October 16, 2013 In a Case statement is there a way to access the value of the Case? Given that you can say " Case 4 To 10" for instance, this would be a useful thing to do. Thanks. Quote
Napivo1972 Posted October 16, 2013 Posted October 16, 2013 (edited) You have the value from your case evaluation that should tell you all you need to know. I am not a VB programmer, so you'll have to do with a C# example switch (value) { case 1: case 2: case 3: // value could be 1, 2 or 3 break; case 4: case 5: case 6: // value could be 4, 5 or 6 break; default: // value can be anything else break; } Here it in in VB Select Case value Case 1, 2, 3 ' value could be 1, 2 or 3 Exit Select Case 4, 5, 6 ' value could be 4, 5 or 6 Exit Select Case Else ' value can be anything else Exit Select End Select Edited October 16, 2013 by Napivo1972 Quote
rbulph Posted October 16, 2013 Author Posted October 16, 2013 You have the value from your case evaluation that should tell you all you need to know. I am not a VB programmer, so you'll have to do with a C# example switch (value) { case 1: case 2: case 3: // value could be 1, 2 or 3 break; case 4: case 5: case 6: // value could be 4, 5 or 6 break; default: // value can be anything else break; } You leave me none the wiser unfortunately. If, as you say, the value could be 1,2 or 3 at this point "// value could be 1, 2 or 3" how do you know which it is? Quote
Napivo1972 Posted October 16, 2013 Posted October 16, 2013 Like this value always contains the value you are looking for. Select Case value Case 1, 2, 3 If value = 1 Then End If If value = 2 Then End If If value = 3 Then End If ' value could be 1, 2 or 3 Exit Select Case 4, 5, 6 Select Case value Case 4 ' value is 4 Case 5 ' value is 5 Case 6 ' value is 6 End Select ' value could be 4, 5 or 6 Exit Select Case Else Exit Select End Select Quote
rbulph Posted October 16, 2013 Author Posted October 16, 2013 Like this Select Case value Case 1, 2, 3 If value = 1 Then End If If value = 2 Then End If If value = 3 Then End If ' value could be 1, 2 or 3 Exit Select Case 4, 5, 6 ' value could be 4, 5 or 6 Exit Select Case Else Exit Select End Select Er, yeah, I suppose so, having a bit of a moment. I was hoping there might be some syntax like "If Case =5 Then" but sure, it's not really necessary. Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.