Hi Greg,
I think you didn't notice the ! character in the comparison string, or
perhaps didn't understand the significance of it. Comparing with
"*[!a-z]*" will return True if the string being checked contains any
character that is not in the range a-z. Therefore it returns False if
the string is _all_ lowercase characters. Invert that result for the
IsLowerCase function.
Comparing with "*[a-z]*" returns True if the string contains any
character that *is* in the range a-z. This of course will return true
if the string is mixed as well as all lowercase. My understanding is
that you want a function that return True only of all the characters
are lowercase.
By the way, I didn't test the function on a zero-length string. As it
happens it returns True for a zero-length string. You'll have to
decide if that is an appropriate result - if not, you'll need to put
in an extra test for a zero-length string
Greg Maxey said:
Johnathan,
This certainly works, but I can't get my head around why it works
when: strIn Like "*[a-z]*" won't work.
It seems your method is saying if zero or more characters from the
start or zero or more chacters endd is not a letter a-z then the
Like Statement is false and the Not Like statement is true.
Wait a minute, perhaps the fog is clearing.
So "*[a-z]*" would mean if zero or more characters from the start or
zero or more chacters end "are" a letter a-z then the statement is
true. strIn = "abc5xyz"
So strIn Like "abc5xyz" would meet that condition and correctly
(while seemingly erroneous) return a True.
I think this how this works. If you have time would you confirm or
offer the correct explanation.
Thanks.
--
Greg Maxey/Word MVP
A Peer in Peer to Peer Support
Jonathan said:
Hi Greg,
I want my Like statement to be true if the string is only lower
case letters.
hmm...
Dim s As String
s = "abcdefghijklmnopQrstuvwxyz"
If LCase(s) = s Then
MsgBox "yes"
Else
MsgBox "no"
End If
Hi Helmut
You might like to check the result of this...
Dim s As String
s = "1234567890-*$£^"
If LCase(s) = s Then
MsgBox "yes"
Else
MsgBox "no"
End If
Again, the solution can be achieved using the Like operator. This
function will do the needful
Function IsLowerCase(strIn As String) As Boolean
IsLowerCase = Not strIn Like "*[!a-z]*"
End Function