Results 1 to 5 of 5

Thread: Like operator acts diff vs in VB6

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Apr 2001
    Location
    N42 29.340 W71 53.215
    Posts
    422

    Like operator acts diff vs in VB6

    In VB.NET using the "Like" operator to compare 2 strings gives me a different result now, as compared to in VB6.

    Is this a bug?

    e.g. ("aza" Like "*a*z*") = False !!!
    yet, ("az" Like "*a*z*") = True (as I would expect)

    Incidentally, I tried doing a search here for "Like" and the search engine didn't like that as a keyword.

    Any ideas? Thanks, DaveBo
    Last edited by DaveBo; Apr 21st, 2005 at 10:55 AM. Reason: Typo
    "The wise man doesn't know all the answers, but he knows where to find them."
    VBForums is one place, but for the really important stuff ... here's a clue 1Tim3:15

  2. #2

    Thread Starter
    Hyperactive Member
    Join Date
    Apr 2001
    Location
    N42 29.340 W71 53.215
    Posts
    422

    Like operator bug

    FWIW, I tried this with both Option Compare Binary and Text - no difference.

    I'm convinced this is a BUG!

    Not a big one maybe, but it did bite me yesterday when I copied one of my more simple and vanilla VB6 routines into a .NET program and it gave me new and wonderfully unexpected results (Never trust a computer!)

    I always used to say "the best thing about computers is they can do the same task faithfully millions of times ... and 2+2 will always equal 4"

    Now I long to take my PC out into a field and use my new peripheral sledge hammer on it.
    Anyone see the movie "Office Space" and the copy machine "incident"?

    DaveBo out
    "The wise man doesn't know all the answers, but he knows where to find them."
    VBForums is one place, but for the really important stuff ... here's a clue 1Tim3:15

  3. #3
    Fanatic Member Graff's Avatar
    Join Date
    Jan 2002
    Location
    Calgary
    Posts
    668

    Re: Like operator acts diff vs in VB6

    I've never used the like operator in either so I'm not 100% sure what the problem is but I know an easy solution. Instead of using Like use the RegEx objects.

    ^.a.z.$

    that is the regular expression that will match *a*z* where * is any single character:

    aaaza = true
    baiza = true
    bbaza = false
    dadzdd = false

    a breakdown of the expression:
    ^ - match beginning
    . - match any single character
    a - match only lowercase a
    z - match only lowercase z
    $ - match end

    if you wanted to match both upper and lowercase you would do the following:
    ^.[aA].[zZ].$


    Here's an excellent site on RegEx in general:
    http://www.regular-expressions.info/
    If wishes were fishes we'd all cast nets.

  4. #4
    Addicted Member
    Join Date
    Jan 2005
    Location
    Montréal
    Posts
    160

    Re: Like operator acts diff vs in VB6

    There are no stupid questions, but a whole bunch of dumb sayings !

    Save time on database code, try DataLG !

  5. #5
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373

    Re: Like operator acts diff vs in VB6

    its the first * in the match pattern that is causing it. I don't have a reason why, it is possible to be a bug.

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