I have this code:
For each c as char in "Hello World"
Select Case c
Case 开发者_JS百科"h"
DoSomething()
Case "e"
DoSomething()
End Select
Next
Why I cant write like this:
Case "h" Or "e"
DoSomething()
It says 'Long' values cannot be converted to 'Char'
How to accomplish this task?
Use:
Select Case c
Case "h"
Case "e"
DoSomething()
End Select
or:
Select Case c
Case "h","e"
DoSomething()
End Select
Case "h", "e"
DoSomething()
if I remember my VB (which is dubious)
The error message appears to be due to it trying a bitwise "or" operation between the two strings, which seems pretty random.
For each c as char in "Hello World"
Select Case c.ToString 'When putting certain objects VB will true/false result of if the string is empty(false) or has text(true).
Case "h", "E"
DoSomething()
Case "e", "H"
DoSomethingElse()
End Select
Next
The case tries to match on c, but c is a char and 'h' or 'e' is a boolean expression. But the cases must have the same type as in the select condition declared.
For solution see Marek G.
精彩评论