Onnesh
Onnesh

Reputation: 1189

need to get out of the select case

We are using a code where we need to select an item in combobox, we do this by a select case statement like Case "SelectItem" However if there are no items in the combobox the code should exit from the case."End Select" was not working..

How can we resolve the same? is there a different logic?

Upvotes: 0

Views: 1811

Answers (3)

Tester101
Tester101

Reputation: 8172

you could try using Case Else to handle any unexpected values.

Select Case SelectItem
     Case 1
          'There is one item in the combobox
     Case 2
          'There are two items in the combobox
     Case Else
          'There are a different number of items
End Select

Not sure what exactly you are doing. You could also wrap your Select in an If statement.

If Combobox.Listcount > 0 Then
     Select Case SelectItem
          Case <Item>
               'Do something here
     End Select
End If

Upvotes: 1

Tara
Tara

Reputation: 615

I'm not sure I entirely understand what you are asking, but I think you may be able to achieve what you want just by putting your select block inside of an if-then. i.e.

If Combobox.Listcount > 0 Then
    Select Case ...
        Case ...
            ...
    End Select
End If

Upvotes: 0

Hans Olsson
Hans Olsson

Reputation: 55029

Unfortunately I don't think there is that functionality. One way to get around it would be to put your Select inside it's own sub and then you can exit it with Exit Sub/Exit Function.

Upvotes: 0

Related Questions