Sign in to follow this  
barkera0

A very easy question about Visual Basic

Recommended Posts

Hi. I'm trying to execute a Select Case statement in Visual Basic. See code:
Select Case Box1.Text

Select Case name
Case "bob" or "joe"
other code here
Case "phil" or "john"
other code here
End Select

End Select
Anyway, when I use those 'or' statements I get an error saying: Conversion from string "bob" to type 'Long' is not valid. To get to this the user entered one of those names into a textbox and clieck a button. How can I get this working?

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Use this instead:

Select Case name
Case "bob", "joe"
' -----------------

Case "phil", "john"
' -----------------

End Select

The "Or" operator is logical and bitwise, and VB assumes you want to logically or bitwisely combine "bob" and "joe". The Select Case statement offers the comma (,) for this purpose.

Share this post


Link to post
Share on other sites
Quote:
Original post by Nice Coder
select case name
case is = "bob" or is = "joe"
code...
end select

Should be what your after
That is not Visual Basic syntax. Why would you post that?

Share this post


Link to post
Share on other sites
Quote:
Original post by iMalc
Quote:
Original post by Nice Coder
select case name
case is = "bob" or is = "joe"
code...
end select

Should be what your after
That is not Visual Basic syntax. Why would you post that?


sorry :( late night and i thought that was how to do that. (forgot about the , )

Post deleted.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this