|
| Author |
Message |
Lorin
Joined: 04 Oct 2007 Posts: 312
|
Posted: Wed Feb 27, 2008 6:17 pm Post subject: Search and Replace |
|
|
VB6SP6
How to do a search and replace in IDE?
e.g. Search for Chr and Replace with Chr$
Code can be
Chr(x) ' want to change this one
MyChr(x) ' do not want to touch this
Cannot do search on Chr(
Whole Word does not include (
I have a whole lot of Chr( Left( Mid( etc to change.
Looking at CodeSmart Demo too and do not see how to do it there.
Archived from group: microsoft>public>vb>general>discussion |
|
| Back to top |
|
 |
Mike Williams
Joined: 04 Oct 2007 Posts: 1309
|
Posted: Thu Feb 28, 2008 2:32 am Post subject: Re: Search and Replace |
|
|
"Lorin" wrote in message @microsoft.com...
> How to do a search and replace in IDE?
> e.g. Search for Chr and Replace with Chr$
> Code can be
> Chr(x) ' want to change this one
> MyChr(x) ' do not want to touch this
> I have a whole lot of Chr( Left( Mid( etc to change.
Do a search and replace for " Chr(" and " Left(" and " Mid(" . . . note the
leading space. This will catch all of them, other than those which appear at
the start of a code line (such as Mid(x,1,1) = " . . . etc). Alternatively,
write your own code in VB and set it to work on your .frm and .vbp files.
That way you will be in total control of what you do. For example, you
could code it so that it performed the task on "Mid(" only iof the character
preceeding it is a space or a chr$(10). This would catch all "Mid(" within a
line of code and also all "Mid(" which are at the start of a code line. And
of course you would deal with the other things in the same way.
Mike |
|
| Back to top |
|
 |
Larry Serflaten
Joined: 04 Oct 2007 Posts: 2644
|
Posted: Wed Feb 27, 2008 8:46 pm Post subject: Re: Search and Replace |
|
|
"Lorin" wrote
>
> How to do a search and replace in IDE?
>
> e.g. Search for Chr and Replace with Chr$
>
> Code can be
> Chr(x) ' want to change this one
> MyChr(x) ' do not want to touch this
The best solution is to avoid 'painting yourself into a corner' like that.
One solution is to simply use the Find Next button to locate those you
do want to change, and hit the Replace button for those, and not for the
ones you don't want touched.
If you do have a lot of references to Chr and MyChr that could be a bit
of work. In that case you could change all occurances of MyChr to MyChar
and then do the Chr change. After you've finished that you can undo MyChar
back to MyChr (or leave it as is).
LFS |
|
| Back to top |
|
 |
Karl E. Peterson
Joined: 04 Oct 2007 Posts: 4836
|
Posted: Wed Feb 27, 2008 7:18 pm Post subject: Re: Search and Replace |
|
|
Mike Williams wrote:
> "Lorin" wrote in message
> @microsoft.com...
>
>> How to do a search and replace in IDE?
>> e.g. Search for Chr and Replace with Chr$
>> Code can be
>> Chr(x) ' want to change this one
>> MyChr(x) ' do not want to touch this
>> I have a whole lot of Chr( Left( Mid( etc to change.
>
> Do a search and replace for " Chr(" and " Left(" and " Mid(" . . . note the
> leading space. This will catch all of them, other than those which appear at
> the start of a code line (such as Mid(x,1,1) = " . . . etc).
Or within another set of parenthesis?
> write your own code in VB and set it to work on your .frm and .vbp files.
> That way you will be in total control of what you do. For example, you
> could code it so that it performed the task on "Mid(" only iof the character
> preceeding it is a space or a chr$(10).
or a "("
--
..NET: It's About Trust!
http://vfred.mvps.org |
|
| Back to top |
|
 |
Lorin
Joined: 04 Oct 2007 Posts: 312
|
Posted: Wed Feb 27, 2008 7:32 pm Post subject: Re: Search and Replace |
|
|
When you inherit code, you do not have much choice other than to fix it the
hard way I guess.
Also, there is more that just MyChr .. lots of other things end in Chr etc.
I may just have to write a VB app to run through and make all those fixes.
Yuck.
"Larry Serflaten" wrote:
>
> "Lorin" wrote
> >
> > How to do a search and replace in IDE?
> >
> > e.g. Search for Chr and Replace with Chr$
> >
> > Code can be
> > Chr(x) ' want to change this one
> > MyChr(x) ' do not want to touch this
>
> The best solution is to avoid 'painting yourself into a corner' like that.
>
> One solution is to simply use the Find Next button to locate those you
> do want to change, and hit the Replace button for those, and not for the
> ones you don't want touched.
>
> If you do have a lot of references to Chr and MyChr that could be a bit
> of work. In that case you could change all occurances of MyChr to MyChar
> and then do the Chr change. After you've finished that you can undo MyChar
> back to MyChr (or leave it as is).
>
> LFS
>
>
> |
|
| Back to top |
|
 |
Mike Williams
Joined: 04 Oct 2007 Posts: 1309
|
Posted: Thu Feb 28, 2008 3:32 am Post subject: Re: Search and Replace |
|
|
"Karl E. Peterson" wrote in message @TK2MSFTNGP03.phx.gbl...
>> Do a search and replace for " Chr(" and " Left(" and " Mid(" . . . note
>> the
>> leading space. This will catch all of them, other than those which appear
>> at
>> the start of a code line (such as Mid(x,1,1) = " . . . etc).
>
> Or within another set of parenthesis?
Yep. Good catch. And there may be other things to watch out for as well. But
if the OP applies a fair amount of though to it then he should easily be
able to write his own code top perform the task, and many other similar
tasks.
Mike |
|
| Back to top |
|
 |
Ken Halter
Joined: 04 Oct 2007 Posts: 4150
|
Posted: Wed Feb 27, 2008 7:33 pm Post subject: Re: Search and Replace |
|
|
"Lorin" wrote in message @microsoft.com...
> VB6SP6
>
> How to do a search and replace in IDE?
>
> e.g. Search for Chr and Replace with Chr$
>
> Code can be
> Chr(x) ' want to change this one
> MyChr(x) ' do not want to touch this
If it were me, I'd probably do something like....
Do a global search/replace, searching for "MyChr" and replacing with "MyCar"
Then
Do a global search/replace, searching for "Chr" and replacing with "Chr$"
Then
Do a global search/replace, searching for "Chr$$" and replacing with "Chr$"
Then
Do a global search/replace, searching for "MyCar" and replacing with "MyChr"
Then
Go make some coffee
--
Ken Halter - MS-MVP-VB - Please keep all discussions in the groups..
In Loving Memory - http://www.vbsight.com/Remembrance.htm |
|
| Back to top |
|
 |
Karl E. Peterson
Joined: 04 Oct 2007 Posts: 4836
|
Posted: Wed Feb 27, 2008 8:03 pm Post subject: Re: Search and Replace |
|
|
Mike Williams wrote:
> "Karl E. Peterson" wrote in message
> @TK2MSFTNGP03.phx.gbl...
>
>>> Do a search and replace for " Chr(" and " Left(" and " Mid(" . . . note the
>>> leading space. This will catch all of them, other than those which appear at
>>> the start of a code line (such as Mid(x,1,1) = " . . . etc).
>>
>> Or within another set of parenthesis?
>
> Yep. Good catch. And there may be other things to watch out for as well.
Oh boy, yeah. I wrote a VBish parser, for kicks, a few years ago:
http://vb.mvps.org/tools/vbmarkup
And these are the characters I used to separate out keywords (for purposes of syntax
highlighting):
Public Function ValidTokens() As String
' This needs to be a function, rather than a module-level
' constant, because of the concatenation to include vbTab.
ValidTokens = ":, ./%&!#@()[]^-+=" & vbTab
End Function
> if the OP applies a fair amount of though to it then he should easily be
> able to write his own code top perform the task, and many other similar
> tasks.
Parsing's a nasty task. But someone's gotta do it.
--
..NET: It's About Trust!
http://vfred.mvps.org |
|
| Back to top |
|
 |
dpb
Joined: 04 Oct 2007 Posts: 568
|
Posted: Wed Feb 27, 2008 10:31 pm Post subject: Re: Search and Replace |
|
|
Mike Williams wrote:
> "Karl E. Peterson" wrote in message
> @TK2MSFTNGP03.phx.gbl...
>
>>> Do a search and replace for " Chr(" and " Left(" and " Mid(" . . .
>>> note the
>>> leading space. This will catch all of them, other than those which
>>> appear at
>>> the start of a code line (such as Mid(x,1,1) = " . . . etc).
>>
>> Or within another set of parenthesis?
>
> Yep. Good catch. And there may be other things to watch out for as well.
....
This thread brings back a _VERY_ painful memory from 30 years ago, now...
DEC-10 TECO, doing a conversion of a CDC-based large simulation code to
the IBM. Since single precision on CDC machines was 60-bit word,
amongst other requirements was the need to change all instances of
single precision constants to double.
We had been working on this translation for roughly six months by this
time and summer brought a sharp young co-op student to help. You can
imagine our chagrin when his first attempt (w/o backing up the working
files) was an overnight batch job which changed all instances of "E" to
"D" globally...
-- |
|
| Back to top |
|
 |
Ralph
Joined: 04 Oct 2007 Posts: 4148
|
Posted: Wed Feb 27, 2008 10:37 pm Post subject: Re: Search and Replace |
|
|
"Lorin" wrote in message@microsoft.com...
> When you inherit code, you do not have much choice other than to fix it
the
> hard way I guess.
> Also, there is more that just MyChr .. lots of other things end in Chr
etc.
>
> I may just have to write a VB app to run through and make all those fixes.
> Yuck.
>
This has come up before. You might want to consider getting an outside
editor that allows multiple buffers, style'ers, keystroke macros, and
built-in RegExp.
I use CodeWright (but can't recommend it, as it is ancient, and the newer
versions are junk IMO). There are lot's of dang good free code editors out
there. And some that are easily worth the nominal charge. They can come in
handy and save a ton of time.
The first thing I do with any "inherited" code or when starting out on a
major refactoring project is to load everything up in a CodeWright project
and re-mangle the lot.
-ralph |
|
| Back to top |
|
 |
Twayne
Joined: 27 Feb 2008 Posts: 2
|
Posted: Thu Feb 28, 2008 4:52 am Post subject: Re: Search and Replace |
|
|
> VB6SP6
>
> How to do a search and replace in IDE?
>
> e.g. Search for Chr and Replace with Chr$
>
> Code can be
> Chr(x) ' want to change this one
> MyChr(x) ' do not want to touch this
>
> Cannot do search on Chr(
> Whole Word does not include (
> I have a whole lot of Chr( Left( Mid( etc to change.
>
> Looking at CodeSmart Demo too and do not see how to do it there.
I think if you tick the "Find Whole Word Only" line you'll be able to
leave out the other ones. Might need to do a couple extra replace runs
depending, but that way "chr(" won't catch "MyChr(", etc.
--
--
Regards,
Twayne
Open Office isn't just for wimps anymore;
OOo is a GREAT MS Office replacement
www.openoffice.org
|
|
| Back to top |
|
 |
|