开发者

Using select enum variable, will it cause an error that the compiler will detect? VB6

In this scenario, What would happen? Would the compiler see an error or would it go undetected? Or would it even cause an error? What should I expect the behavior to be using a select like this?

enum Age  
over18 = 19  
under18 = 17  
end开发者_如何学编程 enum  
...  
...  
Dim myAge As Age

Select case myAge  
case over18   
...  
case under18 
...
End Select

Thanks for the help


I haven't tested it, but I would have thought your code would be fine.

The variable myAge could be set to either over18 or under18 and then the select statement will choose the appropriate branch based on the variable's value.

The compiler shouldn't care that that your enum names do not correspond to the values you have assigned to them, your code maybe confusing for anyone who tried to maintain it in the future though.


I second ipr101's answer, but note that VB doesn't magically know that the under18 enum value should match anything less than 18 so you'd need to check for 0 to 18.

Select case myAge   
case over18 to 999
...   
case 0 to under18  
... 
End Select 

This also means that it no longer fits an enum and a select case structure so a normal If would better suit.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜