Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ending a Case Early

So I have something like the following in Vb6;

Select case Case

case "Case0"
...

case "Case1"
  if Condition Then
     Exit Select
  End If
  *Perform action*

case "Case2"
...

End Select

But for some reason my Exit Select throws the error Expected: Do or For or Sub or Function or Property. I know, not pretty. Should I be using something else? I could just use if statements and not exit the case early, but this would require duplicate code, which I want to avoid. Any help would be really appreciated.

Update

Tried changing Exit Select to End Select and got the error End Select without Select Case. It is definitely within a Select Case and an End Select.

like image 537
windowsgm Avatar asked May 23 '12 14:05

windowsgm


3 Answers

VB doesn't have a facility to exit a Select block. Instead, you'll need to make the contents conditional, possibly inverting your Exit Select conditional.

Select case Case 

case "Case0" 
... 

case "Case1" 
  If Not Condition Then 
    *Perform action* 
  End If 

case "Case2" 
... 

End Select 

Which will have exactly the same end result.

like image 72
Deanna Avatar answered Oct 04 '22 21:10

Deanna


There is no Exit Select Statement in VB6 - only VB.NET

Have a look at the language reference for the Exit Statement - there is no mention of Exit Select

Best option is to refactor your select statements into a new subroutine and then just Exit Sub

like image 28
Matt Wilko Avatar answered Oct 04 '22 21:10

Matt Wilko


Unfortunately, VB6 doesn't have the Exit Select clause available.

This is ony available in VB.NET!

like image 37
Widor Avatar answered Oct 04 '22 19:10

Widor