Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Advanced search&replace in IDE?

1 view
Skip to first unread message

Selecta of JAMRID

unread,
Oct 13, 2005, 7:03:41 AM10/13/05
to
I need to do a find and replace that does this on my code:

Before replace:
variable(i).caption
variable(u).caption
etc...

After replace:
variable(i).value
variable(u).value
etc...

With "variable(*).caption" in the Find filed I find them all, but
"variable(*).value" in the relpace fild gives this result:

variable(*).value
variable(*).value
etc...

Is there a way to acheive what I want?
Can I do this on the .frm file like if they where regular files using
an advanced find/replace tool without corrupting the frm files.

:-) S

hook...@hotmail.com

unread,
Oct 13, 2005, 9:41:22 AM10/13/05
to
Not sure if you're looking for a code or dialog solution.

For code you could put the following in a loop:
Sub ReplaceStrg()
Dim strg As String
strg = "Variable(x).Caption"
Mid$(strg, InStr(1, strg, ".") + 1, 7) = "Value "
Debug.Print Trim(strg)
End Sub

Not so sure if you just wanted to use the Find dialog. Would it be
possible just to do find/replace on the ".caption"??

Hope that helps.
Andrew

Geoff

unread,
Oct 13, 2005, 1:49:33 PM10/13/05
to

"Selecta of JAMRID" <soun...@jamrid.com> wrote in message
news:1129201420....@f14g2000cwb.googlegroups.com...

> I need to do a find and replace that does this on my code:
>
> Before replace:
> variable(i).caption
> variable(u).caption
> etc...
>
> After replace:
> variable(i).value
> variable(u).value
> etc...
>
I see no problems editing the files directly
(other option is to create a VB addin).
Perhaps there is one out there that does this.
Advanced find/replace tool or you could create a
simple app (or addin) to do it
using backreferences with regular expressions
The more involved you get the better the functionality
(assign the Pattern to text box etc)
for doing it simply to support your example hard coded
would not be difficult
texttosearch =read file()
Dim re As New RegExp
Passed = texttosearch
With re
.Pattern = ."(variable\([a-z]\)\.)(Caption)"
.IgnoreCase = True
.MultiLine = True
End With
Result = re.Replace(sv, "$1" & " " & "Value")
End With
If result acceptable Save file(Result)

Passed
variable(i).Caption
variable(u).Caption
Result
variable(i).Value
variable(u).Value

Narrff

unread,
Oct 14, 2005, 11:15:06 PM10/14/05
to
Heya,

If the strings to be changed literally have the indices "i" and
"u", then you're set. To answer your other question : In your specific
case, you can just open the files in a text editor and do the
replacement there. (If you were to replace the word "begin" with
another word, for instance, you would have problems!)

Just an FYI/helpful hint, if you want to open *any* file in notepad
from Explorer's context menu, just add the following registry keys :

HKEY_CLASSES_ROOT\*\shell\EWN\(Default)="Edit with notepad"
HKEY_CLASSES_ROOT\*\shell\EWN\command\(Default)="notepad.exe" "%1"

Although this should go without saying, be extremely careful when
editing the registry, and if you're in doubt, don't do it. :)

HTH,
J.

Selecta of JAMRID

unread,
Oct 17, 2005, 6:15:16 AM10/17/05
to
Thanks,

I'll try a text editor that is a littel more capable then, using
regular expressions. Should work for me. Thanks for the info in regular
expressions by the way, haven't yet tried the examlpe but it should
lead me on the right path.

:-) Mats

Selecta of JAMRID

unread,
Oct 17, 2005, 9:59:16 AM10/17/05
to
Solution:

This does it in Word:

Find box: variable(*).Caption
Relpace box: variable\1.Caption

Mark "Use wildcards" option

Haven't run it on the actual VB .frm files yet, but I suppose you have
to be careful with Word to treat it as plain text file not to get
strange control charachters in the file.

(Just to make sure, I tried the above in the VB IDE. The search work,
but not the replace, at least not in my (pretty old) version.)

:-) Mats

Rick Rothstein [MVP - Visual Basic]

unread,
Oct 17, 2005, 11:41:49 AM10/17/05
to
> (Just to make sure, I tried the above in the VB IDE. The search
work,
> but not the replace, at least not in my (pretty old) version.)

That seems to be the case... the "Use Pattern Matching" option
appears to use the pattern on searches only. If you click the Help
button on the Replace dialog box, this is what it says about this
option...

"Searches using pattern-matching characters."

Note, it only says "searches"; no mention is made about
replacements. I guess Microsoft did not place a true Regular
Expression engine behind this option. Too bad, it would have been
nice (and one would think not too difficult either).

Rick


0 new messages