I found the following pice of VB code in an Access database I am task with maintaining:
sn As String
If Mid(sn, 2, 1) >= "A" And Mid(sn, 2, 1) <= "z" Then
< Do something >
The idea is that if the second character in the string sn is an upper or lower case letter that the code will "do something". However, my read of the ASCII character set says that:
A = 65
Z = 90
[ = 91
\ = 92
] = 93
^ = 94
_ = 95
' = 96
a = 97
z = 122
Since A through Z is 65 throught 90 and a throught z is 97 throught 122 I would expect the characters repersented by 91 through 121 will also allow the do something code to be excuted. However, when I run the code with one of the characters [ / ] ^ _ ' in second position of the string the do something code is not executed?? Why is this?? Is there something about characters in VBA that I am not understanding??
I understand what you are saying. If I were going to rewrite the comparison or modify it in some way I would use Asc() the way you suggest. However, what is the answer to my question, why does the orginal way work??
Then you have the answer. Change it to Option Compare Binary and the test should work the way you want. However, be aware that this modification will affect every string operation (compare, replace, etc.) in the module.