PDA

View Full Version : Solved: = <> vba case sensitive



chungtinhlak
02-19-2009, 02:44 PM
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?


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

Bob Phillips
02-19-2009, 02:51 PM
It is. try



If LCase(Range(focal & usedcell).Value) <> "ray" Then
msgbox ("Does not belong to Ray")
Else
MsgBox ("Belong to Ray")
End If

lucas
02-19-2009, 03:58 PM
Bob, any reason using Option Compare text is not a good solution for this?

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

chungtinhlak
02-19-2009, 04:02 PM
so compare text option make it not case sensitive?

Bob Phillips
02-19-2009, 05:01 PM
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.

lucas
02-19-2009, 05:42 PM
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......

Bob Phillips
02-20-2009, 03:08 AM
Years of experience of debugging old code mate. If you can't learn as you get older, age would be an even bummer rap.