Group:  Microsoft Word ยป microsoft.public.word.newusers
Thread: Help with wildcard search, please?

DotNetBag
.NET Development Newsgroups

HTVi
TV Discussion Newsgroups

Our Hot Pick: Rising Antivirus 2006 - Certified by TUV & Checkmark! Get 10% discount by entering this coupon code: ONDISCOUNT10
Rising Antivirus 2006

Help with wildcard search, please?
"Ed" <ed_millis[ at ]NO_SPAM.yahoo.com> 27.07.2006 16:16:35
I'm trying to use Find (Ctrl+F) with wildcards to find a certain string
ending in a number between 60 and 81. I tried
(App A, Item No. )([60-81]{2})
but it found "App A, Item No. 10". I looked on the Word FAQ page for
Wildcards, but couldn't find how to restrict the number to "more than this
but less than that".

Can this be done with Find, or do I need to go into VBA?

Ed


Re: Help with wildcard search, please?
"Jay Freedman" <jay.freedman[ at ]verizon.net> 27.07.2006 17:21:05
Hi Ed,

Yes, you're going to need VBA. The Find mechanism itself can't do
comparisons of the values of digits. You need something like this:

Dim myRange As Range
Dim myVal As Long

Set myRange = ActiveDocument.Range
FoundIt = False

With myRange.Find
.MatchWildcards = True
.Text = "App A, Item No. ([0-9]{2})"
.Forward = True
.Wrap = wdFindStop
Do While .Execute
myVal = Val(Right$(myRange.Text, 2))
If (60 <= myVal) And (myVal <= 81) Then
myRange.Select ' or do something else
Exit Do
End If
Loop
End With

--
Regards,
Jay Freedman
Microsoft Word MVP FAQ: http://word.mvps.org
Email cannot be acknowledged; please post all follow-ups to the newsgroup so
all may benefit.

Ed wrote:
[Quoted Text]
> I'm trying to use Find (Ctrl+F) with wildcards to find a certain
> string ending in a number between 60 and 81. I tried
> (App A, Item No. )([60-81]{2})
> but it found "App A, Item No. 10". I looked on the Word FAQ page for
> Wildcards, but couldn't find how to restrict the number to "more than
> this but less than that".
>
> Can this be done with Find, or do I need to go into VBA?
>
> Ed


Re: Help with wildcard search, please?
"Klaus Linke" <info[ at ]fotosatz-kaufmann.de> 27.07.2006 17:22:37
"Ed" <ed_millis[ at ]NO_SPAM.yahoo.com> wrote:
[Quoted Text]
> I'm trying to use Find (Ctrl+F) with wildcards to find a certain string
> ending in a number between 60 and 81. I tried
> (App A, Item No. )([60-81]{2})
> but it found "App A, Item No. 10". I looked on the Word FAQ page for
> Wildcards, but couldn't find how to restrict the number to "more than this
> but less than that".
>
> Can this be done with Find, or do I need to go into VBA?


Hi Ed,

Wildcards deal with patterns, and don't have any built-in concept of
numbers. You probably need VBA.

You could use a wildcard search first to find numbers between 60 and 89
([6-8][0-9]), and then you'd need to check the number (last two characters
in the selection) with VBA:

Select Case Val(Right(Selection.Text,2))
Case 60 to 81
' match
End Select

For wildcards to work in this case, you would need an "OR" operator, which
does not exist in Word wildcards:
[6][0-9] OR [7][0-9] OR [8][0-1]

Regards,
Klaus


Re: Help with wildcard search, please?
"Greg Maxey" <gmaxey[ at ]mvps.org> 27.07.2006 17:31:47
I think the closet you can get would be finding 60-89.
App A, Item No. [6-8][0-9][!0-9]

I assumed you wouldn't want to find part of:
App A, Item No. 627

Try:

Sub ScratchMacro()
Dim oRng As Word.Range
Set oRng = ActiveDocument.Range
With oRng.Find
.Text = "App A, Item No. [6-8][0-9][!0-9]"
.MatchWildcards = True
While .Execute
If CLng(Mid(oRng, 17, 2)) < 90 Then
MsgBox oRng.Text
End If
Wend
End With
End Sub


Ed wrote:
[Quoted Text]
> I'm trying to use Find (Ctrl+F) with wildcards to find a certain string
> ending in a number between 60 and 81. I tried
> (App A, Item No. )([60-81]{2})
> but it found "App A, Item No. 10". I looked on the Word FAQ page for
> Wildcards, but couldn't find how to restrict the number to "more than this
> but less than that".
>
> Can this be done with Find, or do I need to go into VBA?
>
> Ed

Re: Help with wildcard search, please?
"Greg Maxey" <gmaxey[ at ]mvps.org> 27.07.2006 17:31:50
I think the closet you can get would be finding 60-89.
App A, Item No. [6-8][0-9][!0-9]

I assumed you wouldn't want to find part of:
App A, Item No. 627

Try:

Sub ScratchMacro()
Dim oRng As Word.Range
Set oRng = ActiveDocument.Range
With oRng.Find
.Text = "App A, Item No. [6-8][0-9][!0-9]"
.MatchWildcards = True
While .Execute
If CLng(Mid(oRng, 17, 2)) < 90 Then
MsgBox oRng.Text
End If
Wend
End With
End Sub


Ed wrote:
[Quoted Text]
> I'm trying to use Find (Ctrl+F) with wildcards to find a certain string
> ending in a number between 60 and 81. I tried
> (App A, Item No. )([60-81]{2})
> but it found "App A, Item No. 10". I looked on the Word FAQ page for
> Wildcards, but couldn't find how to restrict the number to "more than this
> but less than that".
>
> Can this be done with Find, or do I need to go into VBA?
>
> Ed

Re: Help with wildcard search, please?
"Ed" <ed_millis[ at ]NO_SPAM.yahoo.com> 27.07.2006 20:00:43
Huge thanks to all of you Jay, Klaus, and Greg. I really appreciate the
assistance and the codes.

Ed


Re: Help with wildcard search, please?
"Greg Maxey" <gmaxey[ at ]mvps.oSCARrOMEOgOLF> 27.07.2006 21:24:29
Jay,

Are there advantages to Val(someString) over Clng(someString)?

--
Greg Maxey/Word MVP
See:
http://gregmaxey.mvps.org/word_tips.htm
For some helpful tips using Word.

"Jay Freedman" <jay.freedman[ at ]verizon.net> wrote in message
news:eCd4LEasGHA.1196[ at ]TK2MSFTNGP04.phx.gbl...
[Quoted Text]
> Hi Ed,
>
> Yes, you're going to need VBA. The Find mechanism itself can't do
> comparisons of the values of digits. You need something like this:
>
> Dim myRange As Range
> Dim myVal As Long
>
> Set myRange = ActiveDocument.Range
> FoundIt = False
>
> With myRange.Find
> .MatchWildcards = True
> .Text = "App A, Item No. ([0-9]{2})"
> .Forward = True
> .Wrap = wdFindStop
> Do While .Execute
> myVal = Val(Right$(myRange.Text, 2))
> If (60 <= myVal) And (myVal <= 81) Then
> myRange.Select ' or do something else
> Exit Do
> End If
> Loop
> End With
>
> --
> Regards,
> Jay Freedman
> Microsoft Word MVP FAQ: http://word.mvps.org
> Email cannot be acknowledged; please post all follow-ups to the newsgroup
> so all may benefit.
>
> Ed wrote:
>> I'm trying to use Find (Ctrl+F) with wildcards to find a certain
>> string ending in a number between 60 and 81. I tried
>> (App A, Item No. )([60-81]{2})
>> but it found "App A, Item No. 10". I looked on the Word FAQ page for
>> Wildcards, but couldn't find how to restrict the number to "more than
>> this but less than that".
>>
>> Can this be done with Find, or do I need to go into VBA?
>>
>> Ed
>
>


Re: Help with wildcard search, please?
Jay Freedman <jay.freedman[ at ]verizon.net> 28.07.2006 02:58:36
It's mostly that Val is stuck in my memory from about 30 years of use,
and CLng is much more recent. You know the short-term memory is the
first to go. (My wife calls hers "momnesia".)

In most cases, if you assign the result of Val to a Long variable, the
result is identical to what you get from CLng, including the rounding
of non-integers, and the results will compare as equal.

There are some subtle differences, though.

- If the string contains anything other than digits and a decimal
point, Val will evaluate the start of the string up to (but not
including) the non-numeric character. It will also strip out and
ignore spaces, tabs, and line feeds. In the same situations, CLng will
throw a type mismatch error, which needs to be trapped with On Error.

This is not to say that Val is always superior. If you don't carefully
validate the input, Val can give you a number that looks reasonable
but is wrong, where CLng would clearly say "this is garbage".

- Both functions will accept arguments in hexadecimal notation. But
where CLng interprets all hex arguments as positive numbers, Val
interprets 4-digit hex numbers larger than 7FFF as negative numbers
(because the highest-order bit is considered to be a sign bit). You
won't run into this one very often!

--
Regards,
Jay Freedman
Microsoft Word MVP FAQ: http://word.mvps.org
Email cannot be acknowledged; please post all follow-ups to the
newsgroup so all may benefit.

On Thu, 27 Jul 2006 17:24:29 -0400, "Greg Maxey"
<gmaxey[ at ]mvps.oSCARrOMEOgOLF> wrote:

[Quoted Text]
>Jay,
>
>Are there advantages to Val(someString) over Clng(someString)?
>
>--
>Greg Maxey/Word MVP
>See:
>http://gregmaxey.mvps.org/word_tips.htm
>For some helpful tips using Word.
>
>"Jay Freedman" <jay.freedman[ at ]verizon.net> wrote in message
>news:eCd4LEasGHA.1196[ at ]TK2MSFTNGP04.phx.gbl...
>> Hi Ed,
>>
>> Yes, you're going to need VBA. The Find mechanism itself can't do
>> comparisons of the values of digits. You need something like this:
>>
>> Dim myRange As Range
>> Dim myVal As Long
>>
>> Set myRange = ActiveDocument.Range
>> FoundIt = False
>>
>> With myRange.Find
>> .MatchWildcards = True
>> .Text = "App A, Item No. ([0-9]{2})"
>> .Forward = True
>> .Wrap = wdFindStop
>> Do While .Execute
>> myVal = Val(Right$(myRange.Text, 2))
>> If (60 <= myVal) And (myVal <= 81) Then
>> myRange.Select ' or do something else
>> Exit Do
>> End If
>> Loop
>> End With
>>
>> --
>> Regards,
>> Jay Freedman
>> Microsoft Word MVP FAQ: http://word.mvps.org
>> Email cannot be acknowledged; please post all follow-ups to the newsgroup
>> so all may benefit.
>>
>> Ed wrote:
>>> I'm trying to use Find (Ctrl+F) with wildcards to find a certain
>>> string ending in a number between 60 and 81. I tried
>>> (App A, Item No. )([60-81]{2})
>>> but it found "App A, Item No. 10". I looked on the Word FAQ page for
>>> Wildcards, but couldn't find how to restrict the number to "more than
>>> this but less than that".
>>>
>>> Can this be done with Find, or do I need to go into VBA?
>>>
>>> Ed
>>
>>
>
Re: Help with wildcard search, please?
"Greg Maxey" <gmaxey[ at ]mvps.oSCARrOMEOgOLF> 28.07.2006 10:18:48
Thanks Jay.

--
Greg Maxey/Word MVP
See:
http://gregmaxey.mvps.org/word_tips.htm
For some helpful tips using Word.


Jay Freedman wrote:
[Quoted Text]
> It's mostly that Val is stuck in my memory from about 30 years of use,
> and CLng is much more recent. You know the short-term memory is the
> first to go. (My wife calls hers "momnesia".)
>
> In most cases, if you assign the result of Val to a Long variable, the
> result is identical to what you get from CLng, including the rounding
> of non-integers, and the results will compare as equal.
>
> There are some subtle differences, though.
>
> - If the string contains anything other than digits and a decimal
> point, Val will evaluate the start of the string up to (but not
> including) the non-numeric character. It will also strip out and
> ignore spaces, tabs, and line feeds. In the same situations, CLng will
> throw a type mismatch error, which needs to be trapped with On Error.
>
> This is not to say that Val is always superior. If you don't carefully
> validate the input, Val can give you a number that looks reasonable
> but is wrong, where CLng would clearly say "this is garbage".
>
> - Both functions will accept arguments in hexadecimal notation. But
> where CLng interprets all hex arguments as positive numbers, Val
> interprets 4-digit hex numbers larger than 7FFF as negative numbers
> (because the highest-order bit is considered to be a sign bit). You
> won't run into this one very often!
>
>
>> Jay,
>>
>> Are there advantages to Val(someString) over Clng(someString)?
>>
>> --
>> Greg Maxey/Word MVP
>> See:
>> http://gregmaxey.mvps.org/word_tips.htm
>> For some helpful tips using Word.
>>
>> "Jay Freedman" <jay.freedman[ at ]verizon.net> wrote in message
>> news:eCd4LEasGHA.1196[ at ]TK2MSFTNGP04.phx.gbl...
>>> Hi Ed,
>>>
>>> Yes, you're going to need VBA. The Find mechanism itself can't do
>>> comparisons of the values of digits. You need something like this:
>>>
>>> Dim myRange As Range
>>> Dim myVal As Long
>>>
>>> Set myRange = ActiveDocument.Range
>>> FoundIt = False
>>>
>>> With myRange.Find
>>> .MatchWildcards = True
>>> .Text = "App A, Item No. ([0-9]{2})"
>>> .Forward = True
>>> .Wrap = wdFindStop
>>> Do While .Execute
>>> myVal = Val(Right$(myRange.Text, 2))
>>> If (60 <= myVal) And (myVal <= 81) Then
>>> myRange.Select ' or do something else
>>> Exit Do
>>> End If
>>> Loop
>>> End With
>>>
>>> --
>>> Regards,
>>> Jay Freedman
>>> Microsoft Word MVP FAQ: http://word.mvps.org
>>> Email cannot be acknowledged; please post all follow-ups to the
>>> newsgroup so all may benefit.
>>>
>>> Ed wrote:
>>>> I'm trying to use Find (Ctrl+F) with wildcards to find a certain
>>>> string ending in a number between 60 and 81. I tried
>>>> (App A, Item No. )([60-81]{2})
>>>> but it found "App A, Item No. 10". I looked on the Word FAQ page
>>>> for Wildcards, but couldn't find how to restrict the number to
>>>> "more than this but less than that".
>>>>
>>>> Can this be done with Find, or do I need to go into VBA?
>>>>
>>>> Ed


Home | Search | Terms | Imprint | Contact
Newsgroups Reader - provided by WiredBox.Net