CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6
  1. #1
    Join Date
    May 2001
    Location
    Canada
    Posts
    182

    "in" operator in VB?

    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

  2. #2
    Join Date
    Jun 2001
    Location
    Memphis, TN
    Posts
    146

    Re: "in" operator in VB?

    Try this maybe...


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





  3. #3
    Join Date
    May 2001
    Location
    Canada
    Posts
    182

    Re: "in" operator in VB?

    Yes, it is a work around if there is no such operator. Thanks.

    Regards,

    Michi
    MCSE, MCDBA

  4. #4
    Join Date
    Jul 2001
    Posts
    5

    Re: "in" operator in VB?

    Like = is a new Vb6 operator
    ie:
    if x like "[a-b-c]" or x like "[A-B-C]" then
    end if


  5. #5
    Join Date
    Jul 2000
    Location
    Milano, Italy
    Posts
    7,726

    Re: Correct sintax for Like


    '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
    ...at present time, using mainly Net 4.0, Vs 2010



    Special thanks to Lothar "the Great" Haensler, Chris Eastwood , dr_Michael, ClearCode, Iouri and
    all the other wonderful people who made and make Codeguru a great place.
    Come back soon, you Gurus.

  6. #6
    Join Date
    May 2001
    Location
    Canada
    Posts
    182

    Re: Correct sintax for Like

    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured