Jump to content


Photo
- - - - -

Code To Change Code


  • Please log in to reply
5 replies to this topic

#1 Ziggy54354

Ziggy54354

    OCC's Sexiest Asian

  • Members
  • PipPipPipPip
  • 1495 posts

Posted 06 August 2008 - 10:09 AM

Is there a way to have a macro do a find and replace of code that is in a project? I'm changing the names of a bunch of bookmarks and I would like to automatically change the names of the bookmarks in the code to what I am changing them to. Does anyone know if this is possible?
Current Rig:

Intel E8400 4ghz | DFI Blood-Iron P35 | EVGA 9800GTX+
2x 320GB Seagate 1x 500GB Seagate 1x 1.5TB Seagate | 4GB G.Skill pc8000 PQ


Ubuntu Rig:

AXP 1.4ghz 200FSB 7x | Abit NF-7s | 6800GS
200GB Seagate | 1gb Corsair XMS pc3200 2-2-2-11


#2 ARandomOWL

ARandomOWL

    Wise Owl

  • FW Team Member
  • PipPipPipPip
  • 1458 posts
  • Gender:Male
  • Location:UK

Posted 06 August 2008 - 11:27 AM

What program are u using? Doesn't it have a find & replace function?

4670k + GTX 980Ti -- crammed into a mini-ITX case

Arch Linux

About Me


#3 Propane

Propane

    ??? Ohio Alpha

  • Members
  • PipPipPipPipPip
  • 4090 posts
  • Gender:Male
  • Location:Ohio

Posted 06 August 2008 - 06:35 PM

Find and replace / refactoring tools...

example as how it would be done in my favorite editor vim:
:%s/old_text/new_text/gc

That will replace all old_text (can be a regex) to new_text, and every occurrence it finds will prompt you if you want the change to be made... pressing y will change it, pressing n will move on.


.:: Kevin Cramer Photography ::.
.:: facebook :: last.fm :: twitter :: flickr :: you tube :: blog :: occ reviews ::.
Posted Image
Posted Image
"Here's to alcohol: the cause of, and solution to, all of life's problems." -Homer Simpson
Follow OCC on Posted Image


#4 Waco

Waco

    Lab Rat 2

  • Members
  • PipPipPipPipPipPipPipPip
  • 16508 posts
  • Gender:Male
  • Location:Los Alamos, NM

Posted 06 August 2008 - 07:02 PM

It totally depends on what you are using. I can't think of many editors that don't have a Find/Replace prompt or command though...

Tolerance is a sign of weakness.


#5 Nemo

Nemo

    Will Fold 4 Food

  • Honorary Staff
  • PipPipPipPipPipPip
  • 7228 posts
  • Gender:Male
  • Location:Franklin, TN

Posted 06 August 2008 - 07:31 PM

Since you're working with VBA, then the easiest way would be to just use the built-in editor to do a find and replace. You can do a replace all if you're confident you know you won't accidental change something that you shouldn't. If you hit Ctl+H while in your project, you can specify to original text and replacement text, tell it where to search - current procedure, current project, etc., specify Match Case and Whole Word and then hit replace all.

If you have some abnormally large number of changes to make, you could write code to parse the code, but a manual search and replace would probably be done before you could write and test the code.

But, just for grins and giggles, you can export the code containing your macros to a text file - there's an export function under the File option on the menu bar. It'll have a .bas file extension, but is really a plain text file you can look at using any text editor like Notepad. You could then write VBA code to open the .bas file as a File System Object and parse the text to do a find and replace. Once you're done, you can import the file back into your project. Not too hard to do, but a lot more trouble than it's worth if you ask me.

Intel Core 2 Quad Q9550 2.83GHz / ASUS P5Q Deluxe / Patriot Extreme Performance 2GB PC2-9600 DDR2-1200MHz / 2x Seagate ST3160827AS 160GB RAID 1 / Seagate ST31000340AS 1TB
Corsair TX750W / Sapphire HD 5870 1GB GDDR5 / SilverStone TJ05 / Scythe Zipang 140mm CPU Cooler / ASUS VH202T-P 20" widescreen monitor (x2) / XP Pro SP 3
"however, i cannot claim to be such a fish as i am not a fish at all..." - hardnrg,Jul 4 2005, 02:49 PM
 

Posted Image

Posted Image

Follow OCC on Posted Image
Subscribe to the OCC Newsletter

Lucky Mudder Race 2013


#6 Ziggy54354

Ziggy54354

    OCC's Sexiest Asian

  • Members
  • PipPipPipPip
  • 1495 posts

Posted 07 August 2008 - 05:27 AM

I was trying to avoid find and replace as that would be manual and i would have to do thousands of these but I found a perfect solution. Check out the following if you guys are interested. http://pubs.logicale...icle.asp?ID=307 and http://www.cpearson.com/excel/vbe.aspx
Current Rig:

Intel E8400 4ghz | DFI Blood-Iron P35 | EVGA 9800GTX+
2x 320GB Seagate 1x 500GB Seagate 1x 1.5TB Seagate | 4GB G.Skill pc8000 PQ


Ubuntu Rig:

AXP 1.4ghz 200FSB 7x | Abit NF-7s | 6800GS
200GB Seagate | 1gb Corsair XMS pc3200 2-2-2-11