tags:

views:

688

answers:

2

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
or UCase would do the same thing.
Szere Dyeri
Or use StrComp(strVal1, strVal2, vbTextCompare)
Tomalak
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
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
Amend made as suggested.
Jon Hopkins
Option Compare is evil!
rpetrich
+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