Consulting

Results 1 to 7 of 7

Thread: Solved: = <> vba case sensitive

  1. #1
    VBAX Tutor
    Joined
    Dec 2008
    Posts
    244
    Location

    Solved: = <> vba case sensitive

    is it true that in vba, operators are cased sensitive?

    I use the following code and it's cased sensitive. In the cell, ray is all cap. is try ray and Ray and it does not work, when i RAY it work.

    all these time, i thought that vba is not cased sensitive?

    [VBA]
    If Range(focal & usedcell).Value <> "ray" Then
    msgbox ("Does not belong to Ray")
    Else
    MsgBox ("Belong to Ray")
    [/VBA]

  2. #2
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    It is. try

    [vba]

    If LCase(Range(focal & usedcell).Value) <> "ray" Then
    msgbox ("Does not belong to Ray")
    Else
    MsgBox ("Belong to Ray")
    End If
    [/vba]
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  3. #3
    Moderator VBAX Wizard lucas's Avatar
    Joined
    Jun 2004
    Location
    Tulsa, Oklahoma
    Posts
    7,323
    Location
    Bob, any reason using Option Compare text is not a good solution for this?

    [VBA]Option Explicit
    Option Compare Text
    Sub a()
    If Range("A1").Value <> "ray" Then
    MsgBox ("Does not belong to Ray")
    Else
    MsgBox ("Belong to Ray")
    End If
    End Sub
    [/VBA]
    Steve
    "Nearly all men can stand adversity, but if you want to test a man's character, give him power."
    -Abraham Lincoln

  4. #4
    VBAX Tutor
    Joined
    Dec 2008
    Posts
    244
    Location
    so compare text option make it not case sensitive?

  5. #5
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Quote Originally Posted by lucas
    Bob, any reason using Option Compare text is not a good solution for this?
    I never use it Steve, can never remember what its setting is. Anyway, I am not a fan of implicit settings (witness my rants against default values), so I prefer being explicit and descriptive in my code.
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  6. #6
    Moderator VBAX Wizard lucas's Avatar
    Joined
    Jun 2004
    Location
    Tulsa, Oklahoma
    Posts
    7,323
    Location
    That answers my question Bob. Thanks and I hope to be as conscientious as you are one day......takes dedication.

    Good insights.

    I do use it in cases like this but only if there are no other procedures in the module that might be affected by it besides the one I am concerned with......
    Steve
    "Nearly all men can stand adversity, but if you want to test a man's character, give him power."
    -Abraham Lincoln

  7. #7
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Years of experience of debugging old code mate. If you can't learn as you get older, age would be an even bummer rap.
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

Posting Permissions

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