help with a select case

Jon123

Registered User.
Local time
Today, 01:58
Joined
Aug 29, 2003
Messages
668
when creating a select case it goes
Select case [something]

Case "1"
If myvariable = cbxx then
i want to end the case here
else
do this
end if
Case "2"
etc etc

end select

so is there a way to stop the case if the if statment is true?


jim
 
Once a Select Case encounters a True condition, it executes the relevant code and then Exits the Select control structure. In other words, it's done, and doesn't proceed to test any remaining Case statements.

Not sure if this was the essence of your question.
 
but i am not sure whether

case "1"
case "2" text for numbers or strings

if you have a number it should really be just

case 1:
case 2:
 
As JJ stated - once a case is encountered that matches the item being compared, it follows that path and then exits. It does not test all cases unless it works its way through and doesn't find one that matches. That is what a Case Else is for so you can handle anything for which there is no match. But, you also have to be careful as to what you test because if you had something like my sample below you would find that it would not go to the next Case if I had something like this:

Code:
Select Case MyVariable
Case <100
   Msgbox "This is less than 100"
Case <=75 
   Msgbox "This is less than or equal to 75"
End Select
In that example if I passed anything less than 100 it would never test the second case statement as the value has already passed the first case statement. So, in this case I COULD write this and it would catch all below or equal to 75 and then the second would catch anything between 76 and 99

Code:
Select Case MyVariable
Case <=75
   Msgbox "This is less than 100"
Case <100 
   Msgbox "This is less than or equal to 75"
End Select

So the second case statement essentially (and practically if you wanted simplicity) would work the same as if you said:
Case 76 to 99
 

Users who are viewing this thread

Back
Top Bottom