if strValue = 'Hello' then what would be the value of (strValue <> 'HELLO') be?
- 1Wouldn't it be easier - and more certain - to write an incredibly simple test for this?Carl Manaster– Carl Manaster2009-05-01 21:20:10 +00:00Commented May 1, 2009 at 21:20
- Carl, I was about to say that. Most people don't have a VB6 interpreter around, but the OP obviously does. :)Matthew Flaschen– Matthew Flaschen2009-05-01 21:22:43 +00:00Commented May 1, 2009 at 21:22
- Though VBA behaves the same and most people do have that...Jon Hopkins– Jon Hopkins2009-05-01 21:24:55 +00:00Commented May 1, 2009 at 21:24
- @Carl - Sure, simple unit tests on classic ASP VB code with no reliable debugging tool sound great. Or you could not put a comment here and actually answered the question.RSolberg– RSolberg2009-05-01 22:31:15 +00:00Commented May 1, 2009 at 22:31
- I'm joking. i don't have a vb6 environment set up and literally looking at code with sourcesafe's viewer.Jon Erickson– Jon Erickson2009-05-01 22:32:02 +00:00Commented May 1, 2009 at 22:32
3 Answers
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.
Comments
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.
4 Comments
The documentation is fairly clear
If you use
Option Compare Textin the Declarations section of a module [the top of the file], string comparisons aren't case-sensitive.
If you useOption Compare Binary, comparisons are case-sensitive.
If you useOption Compare Database[only valid in Access VBA], the comparison method is set by the current database.