Вопрос

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.

Это было полезно?

Решение

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.

Другие советы

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

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

This is ony available in VB.NET!

Try this

Do
    Select case Case

    case "Case0"
    ...

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

    case "Case2"
    ...

    End Select
Loop While False

Edit: Btw, I wouldn't hesitate to use GoTo in this case (and not only this).

just discovered some thing very trivial does the trick:

Select case Case 

case "Case0" 
... 

case "Case1" 
  A=A

case "Case2" 
... 

End Selec

Just to answer this old question the other way you can also use GoTo:

Select case Case

case "Case0"
...

case "Case1" 'you can use not condition as stated

  if Condition Then GoTo Exit_select
  *Perform action*

case "Case2"
...
Exit_select:
End Select
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top