if strValue = 'Hello' then what would be the value of (strValue <> 'HELLO') be?
+6
A:
No, it's case sensitive (by default at least though you'll want to check - if Option Compare is set to Binary or not set then it's case sensitive, if it's set to text then it's case insensitive).
Lcase() both sides if you'd rather it were case insensitive.
The reason I prefer this to changing / setting option compare is that someone looking at the code doesn't have to go hunting to see what option compare is set to to understand how it's going to behave BUT it's almost certainly slower (not significantly unless you're calling it repeatedly) and some might see it as not particularly neat.
Jon Hopkins
2009-05-01 21:17:46
or UCase would do the same thing.
Szere Dyeri
2009-05-01 21:20:03
Or use StrComp(strVal1, strVal2, vbTextCompare)
Tomalak
2009-05-01 22:22:14
Might be worth saying that the reason I do this rather than use option compare is that I prefer to make it explicit in the comparison rather than have someone reading the code find something which modified the default behaviour.
Jon Hopkins
2009-05-02 07:45:59
Partly wrong, it's not always case sensitive. It depends on the Option Compare setting in the source file. (As you obviously know from your comment - you might want to modify your answer?) Another reason for avoiding non-default Option Compare settings is it lays a trap for anyone who copies the routines to another project.
MarkJ
2009-05-02 09:49:36
Amend made as suggested.
Jon Hopkins
2009-05-02 13:20:35
Option Compare is evil!
rpetrich
2009-05-03 19:38:47
+11
A:
It depends on how you use the Option Compare statement. It can work either way.
Option Compare Text 'Case insensitive'
Option Compare Binary 'Case sensitive (default)'
Here's a VB6 string tutorial.
Jon B
2009-05-01 21:18:24