A recent comment about Case Select caused me to look a little deeper in to pool of knowledge.... and its far to profound for me.
When would you use Switch rather than Case Select given the following examples
andSub select_case_example() 'Greater 1000 case will not trigger since cases are done in order. 'Must change order if you want to check both conditions 'Include else statement at bottom to capture other conditions Dim our_input As Integer our_input = InputBox("Enter an integer") Select Case our_input Case Is < 500 MsgBox ("Your input is less than 500") Case Is > 500 MsgBox ("Your input is greater than 500") Case Is > 1000 MsgBox ("Your input is greater than 1000") End Select End Sub
Sub using_switch_function_result() 'Greater 1000 case will not trigger since function resolves in order. 'Must change order if you want to check both conditions. Dim our_input As Integer Dim our_output As String our_input = InputBox("Enter an integer") our_output = Switch(our_input < 500, "Your input is less than 500", our_input > 500, "Your input is greater than 500", our_input > 1000, "Your input is greater than 1000") MsgBox (our_output) End Sub




Reply With Quote
