Reputation: 2613
I have this code:
For each c as char in "Hello World"
Select Case c
Case "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?
Upvotes: 3
Views: 399
Reputation: 11
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
Upvotes: 1
Reputation: 3301
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.
Upvotes: 0
Reputation: 17353
Use:
Select Case c
Case "h"
Case "e"
DoSomething()
End Select
or:
Select Case c
Case "h","e"
DoSomething()
End Select
Upvotes: 8
Reputation: 1062915
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.
Upvotes: 3