an simple ?

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Why does this happen:
x="HI"
y="Hi"

if x<>y then
...do something
end if

But the code never does anything because it thinks x DOES equal y!
I need to know if Title Case has changed the string...
thanks,
ck
 
In
Charlie said:
Why does this happen:
x="HI"
y="Hi"

if x<>y then
...do something
end if

But the code never does anything because it thinks x DOES equal y!
I need to know if Title Case has changed the string...

String comparisons in VBA are not case-sensitive unless Option Compare
Binary is in effect (which it isn't, by default). But you can always
make a case-sensitive comparison using the StrComp function, specifying
vbBinaryCompare for the optional Compare argument:

?"Hi"="HI"
True
?(StrComp("Hi", "HI", vbBinaryCompare) = 0)
False
 
Access expressions are not sensitive to case so "Hi" is the same as "HI".
The code is operating correctly. If you want to distinguish the difference,
you could compare both strings one character at a time using the ASCII value
of the characters. Doing this, the ASCII value of "i" <> the ASCII value of
"I", x <> y and your code would do something.

PC Datasheet
Providing Customers A Resource For Help With Access, Excel And Word
Applications
(e-mail address removed)
 
Back
Top