开发者

Select Case problem

开发者 https://www.devze.com 2023-03-11 16:24 出处:网络
I have this code: For each c as char in \"Hello World\" Select Case c Case 开发者_JS百科\"h\" DoSomething()

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.

0

精彩评论

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