Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

breaking out of a "select case"

Status
Not open for further replies.

kirk2364

Programmer
May 3, 2001
10
CA
I have extensive logic in each case of a case statement. I need to, when one if statement resolves to true, break out of the entire case statement. JavaScript has a "break;" but what's the equivalent in VBScript?
 
It si automatic. VB Case does not "fall through". When a Case is met, it executes the code below the Case until the next Case or End Select and branches pass the corresponding End Select.
 
I don't think I have clearly defined the issue. There is logic inside the case argument, but I do not want to complete the logic. I need to break early. Maybe this "diagram" can help:

select case varName
case "a"
if blah blah blah then
break out of the entire case statement now
end if
more processing
blah
blah
case "b"
blah
end select
 
There is not an Exit Select but use this handy "trick".
Code:
Do
  select case varName
    case "a"
      if blah blah blah then
         Exit DO
      End If
      more processing
      blah
      blah
   case "b"
      blah
  end select
Exit Do: Loop  ' Unconditional exit - Loop for Syntax
 
Thanks so much for your help. I'll give it a try. I guess the other way to do it is to use an "else" and put the "end if" right at the bottom of the case logic.

Thanks again!
 
select case varName
case "a"
if blah blah blah then
GoTo NxtItem
break out of the entire case statement now
end if
more processing
blah
blah
NxtItem:
case "b"
blah
end select



MichaelRed
redmsp@erols.com

There is never time to do it right but there is always time to do it over
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top