6

if strValue = 'Hello' then what would be the value of (strValue <> 'HELLO') be?

8
  • 1
    Wouldn't it be easier - and more certain - to write an incredibly simple test for this? Commented 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. :) Commented May 1, 2009 at 21:22
  • Though VBA behaves the same and most people do have that... Commented 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. Commented 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. Commented May 1, 2009 at 22:32

3 Answers 3

12

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.

Sign up to request clarification or add additional context in comments.

Comments

11

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

or UCase would do the same thing.
Or use StrComp(strVal1, strVal2, vbTextCompare)
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.
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.
2

The documentation is fairly clear

If you use Option Compare Text in the Declarations section of a module [the top of the file], string comparisons aren't case-sensitive.
If you use Option Compare Binary, comparisons are case-sensitive.
If you use Option Compare Database [only valid in Access VBA], the comparison method is set by the current database.

1 Comment

Hello whoever downvoted this. Care to leave a comment?

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.