views:

631

answers:

5
Enum age

 Over18

 Under18

End enum


Select case age

End select

'age' is a type and cannot be used as an expression.

Is there any way of using enums in "select case"?

+5  A: 

That doesn't make sense. But you can do a Select Case on a variable that has the enum as its type.

Dim customerAge As age
customerAge = age.Over18

Select Case customerAge
    Case age.Over18
        ...
    Case age.Under18
        ...
End Select
Jacob
A: 

I wouldn't think so. The Select Case is just a special If Then statement so the select has to have something to compare the answer to. So

Select childsAge
Case age.Over18
GarrettD78
+1  A: 

The enum "age" is indeed a type. You need to assign it to a variable built to hold it and test it that way:

Enum age
  over18
  under18
End enum


user.age = age.over18

Select case user.age

End Select
Chris McCall
+2  A: 

You will have to define a variable that uses the enum.


   dim myage as age
    myage = age.Over18

    Select Case myage
    case age.Over18
    .....
    case age.Under18
    .....
    end select

shahkalpesh
A: 

you can't use the type (age) on the expression, but you can use any variables of that type

Dim myAge As age

Select Case myAge Case age.Over18...

BlackTigerX