Click to See Complete Forum and Search --> : "in" operator in VB?


michi
August 1st, 2001, 03:40 PM
Hi,

Is there any Operator like "in" in VB which have the similar function as in SQL?

What I want to do is:


if x="a" or x="b" or x="c" then
'do something
end if

May I use this:
if x in ("a","b","c") then
'do something
end if

Thanks!


Regards,

Michi
MCSE, MCDBA

Ghost308
August 1st, 2001, 03:46 PM
Try this maybe...


Select Case x
case "a" or "b" or "c":
'do something
End Select

michi
August 1st, 2001, 03:49 PM
Yes, it is a work around if there is no such operator. Thanks.

Regards,

Michi
MCSE, MCDBA

TheAvenger
August 6th, 2001, 07:17 AM
Like = is a new Vb6 operator
ie:
if x like "[a-b-c]" or x like "[A-B-C]" then
end if

Cimperiali
August 7th, 2001, 02:08 AM
'this does work
private Sub Command1_Click()

Dim vntIn
vntIn = InputBox("input a letter")
If vntIn Like "[A-C]" then
MsgBox "input= A,B or C"
ElseIf vntIn Like "[DEFabc]" then
MsgBox "input = D,E,F, a,b or c"
ElseIf vntIn Like "*#" then
MsgBox "input: a keystroke and a number"
End If

End Sub




Special thanks to Lothar "the Great" Haensler, Tom Archer, Chris Eastwood, TCartwright, Bruno Paris
and all the other wonderful people who made and make Codeguru a great place.
Come back soon, you Gurus.

The Rater

michi
August 7th, 2001, 11:32 AM
Thanks for your suggestion. But I think the "Like" operator does not very useful when the selective strings have no comparison part except for the meanings. For example, how can we use "like" to translate the following:

If x in ("cat", "dog", "fish") then .....

Anyway, thanks again.


Regards,

Michi