Is there any way to construct a wildcard Like statement similar to the {1,}
one or more of the proceding character used in Find? Here is an example. I
want my Like statement to be true if the string is only lower case letters.
I get a a match if I use [a-z] followed by 25 asterisks. Is this statement
really limited in this area? Thanks

Sub Test()
Dim MySting As String

MyString = "abcdefghijklmnopqrstuvwxyz"

If MyString Like "[a-z]************************" Then MsgBox "Eureka"
'What I would like to do:
'If MyString Lik "[a-z]{1,}" Then ...
End Sub


--
Greg Maxey/Word MVP
A Peer in Peer to Peer Support

Re: Like Statement by Andi

Andi
Fri Jan 14 03:20:16 CST 2005

On Thu, 13 Jan 2005 21:02:48 -0500, "Greg Maxey"
<gmaxey@mvps.OscarRomeoGolf> wrote:

>Is there any way to construct a wildcard Like statement similar to the {1,}
>one or more of the proceding character used in Find? Here is an example. I
>want my Like statement to be true if the string is only lower case letters.
>I get a a match if I use [a-z] followed by 25 asterisks. Is this statement
>really limited in this area? Thanks
>
>Sub Test()
>Dim MySting As String
>
>MyString = "abcdefghijklmnopqrstuvwxyz"
>
>If MyString Like "[a-z]************************" Then MsgBox "Eureka"
>'What I would like to do:
>'If MyString Lik "[a-z]{1,}" Then ...
>End Sub

I have seen a while ago a post about a regular-expression function,
but forgot if it's a programm or a dll (free or included in Windows)

But I never tried it, because I like my ASC approach much more and
have 100% control.

Sub check_aTOz(MyString as string)
Dim Nr As Long, I As Long
For I = 1 To Len(Mystring)
Nr = Asc(Mid(Mystring, I, 1))
If Nr < 97 Or Nr > 122 Then
MsgBox "Sorry the " & I & " letter is not [a-z]"
Exit For
End If
Next I
If I > Len(Mystring) Then MsgBox "Eureka"
End Sub


---
If you expect an answer to a personal mail, add the word "manfred" to the first 10 lines in the message
MW

Re: Like Statement by Greg

Greg
Fri Jan 14 04:45:16 CST 2005

Thanks Andi.

--
Greg Maxey/Word MVP
A Peer in Peer to Peer Support

Andi Mayer wrote:
> On Thu, 13 Jan 2005 21:02:48 -0500, "Greg Maxey"
> <gmaxey@mvps.OscarRomeoGolf> wrote:
>
>> Is there any way to construct a wildcard Like statement similar to
>> the {1,}
>> one or more of the proceding character used in Find? Here is an
>> example. I
>> want my Like statement to be true if the string is only lower case
>> letters.
>> I get a a match if I use [a-z] followed by 25 asterisks. Is this
>> statement
>> really limited in this area? Thanks
>>
>> Sub Test()
>> Dim MySting As String
>>
>> MyString = "abcdefghijklmnopqrstuvwxyz"
>>
>> If MyString Like "[a-z]************************" Then MsgBox "Eureka"
>> 'What I would like to do:
>> 'If MyString Lik "[a-z]{1,}" Then ...
>> End Sub
>
> I have seen a while ago a post about a regular-expression function,
> but forgot if it's a programm or a dll (free or included in Windows)
>
> But I never tried it, because I like my ASC approach much more and
> have 100% control.
>
> Sub check_aTOz(MyString as string)
> Dim Nr As Long, I As Long
> For I = 1 To Len(Mystring)
> Nr = Asc(Mid(Mystring, I, 1))
> If Nr < 97 Or Nr > 122 Then
> MsgBox "Sorry the " & I & " letter is not [a-z]"
> Exit For
> End If
> Next I
> If I > Len(Mystring) Then MsgBox "Eureka"
> End Sub
>
>
> ---
> If you expect an answer to a personal mail, add the word "manfred" to
> the first 10 lines in the message MW



Re: Like Statement by Helmut

Helmut
Fri Jan 14 05:11:40 CST 2005

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

Greetings from Bavaria, Germany

Helmut Weber, MVP
"red.sys" & chr(64) & "t-online.de"
Word XP, Win 98
http://word.mvps.org/


Re: Like Statement by Jonathan

Jonathan
Fri Jan 14 05:26:17 CST 2005


"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


--
Regards
Jonathan West - Word MVP
www.intelligentdocuments.co.uk
Please reply to the newsgroup


Re: Like Statement by Greg

Greg
Fri Jan 14 13:00:11 CST 2005

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



Re: Like Statement by Jonathan

Jonathan
Sat Jan 15 15:47:08 CST 2005

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
>
>



Re: Like Statement by Greg

Greg
Sat Jan 15 16:44:40 CST 2005

Jonathan,

No I did see your "!" and was able to get your method to work. I was
struggling with why If MyString Like "*[a-z]*" wouldn't work.

I understand now that "*[a-z]*" means if any character in the string is in
the a-z range then the expression is true. I was thinking earlier that
"all" characters in the string would have to be in the a-z range or the
expression would be false.

Thanks for you help.

--
Greg Maxey/Word MVP
A Peer in Peer to Peer Support

Jonathan West wrote:
> 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" <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



Re: Like Statement by Poseur

Poseur
Tue Jan 18 07:54:24 CST 2005

Andi Mayer <andi_mayer@gmx.at> wrote in
news:2h2fu0ts6594357ab5oq6aclhvhhrp7nu6@4ax.com:

> On Thu, 13 Jan 2005 21:02:48 -0500, "Greg Maxey"
> <gmaxey@mvps.OscarRomeoGolf> wrote:
>
>
> I have seen a while ago a post about a regular-expression
> function, but forgot if it's a programm or a dll (free or
> included in Windows)
>
> But I never tried it, because I like my ASC approach much
> more and have 100% control.
As do I now that I've seen it.
As for pre- .NET regular expressions, it is free, you need to add
the reference to the library: Microsoft VBScript Regular
Expression 5.5

Dim rgExp As VBScript_RegExp_55.RegExp
Set rgExp = New VBScript_RegExp_55.RegExp
With rgExp
.Pattern = "\swhatever\!"
.Global = True
.IgnoreCase = False
.Replace(someRange.Text, "something better")
End With

In the VBScript help file, VBSCRIP5.CHM.
Works quite well, no performance decrement I can tell (but haven't
done metrics).
Constrained by the weird .doc file format somewhat.
--
Poseur
"That's just kooky talk." --Kramer