Re: Like Statement
From: Jonathan West (jwest_at_mvps.org)
Date: 01/15/05
- Next message: Cabunk: "Creating Pop-up windows in Word 2003"
- Previous message: Peter: "Exporting data into a MS Word Serial Letter via ASP"
- In reply to: Greg Maxey: "Re: Like Statement"
- Next in thread: Greg Maxey: "Re: Like Statement"
- Reply: Greg Maxey: "Re: Like Statement"
- Messages sorted by: [ date ] [ thread ]
Date: Sat, 15 Jan 2005 21:47:08 -0000
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
-- Regards Jonathan West - Word MVP www.intelligentdocuments.co.uk Please reply to the newsgroup "Greg Maxey" <gmaxey@mvps.OscarRomeoGolf> wrote in message news:%23LRPDtm%23EHA.4092@TK2MSFTNGP09.phx.gbl... > 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 West wrote: >> "Helmut Weber" <elmkqznfwvccbf@mailinator.com> wrote in message >> news:23afu059co7nbddp9fj9l2are9sir3uaoc@4ax.com... >>> 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 > >
- Next message: Cabunk: "Creating Pop-up windows in Word 2003"
- Previous message: Peter: "Exporting data into a MS Word Serial Letter via ASP"
- In reply to: Greg Maxey: "Re: Like Statement"
- Next in thread: Greg Maxey: "Re: Like Statement"
- Reply: Greg Maxey: "Re: Like Statement"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|