Go Back   Tactical Gamer > General Forums > Hardware & Software Discussion


Hardware & Software Discussion Hardware and Software discussion and troubleshooting. Tweakers and Overclockers welcome!

Reply
 
Thread Tools
Old 05-18-2007, 05:26 PM   #1 (permalink)
 
icky's Avatar
 
Join Date: Jul 2005
Location: Ottawa Valley
Posts: 6,154
Visual Studio macros help?

I'm taking a shot in the dark here, but I figure maybe someone in this community has worked with VB macros in Visual Studio and can help me.

I am working on a simple macro, but I've never worked with VB or the macro editor in any way besides the most basic changes to other people's macros.

I have lots of long arrays in C++ code initialized like this
a[0] = &blah1;
a[1] = &blah7;
a[2] = &blah13;
...
a[49] = &blahblah985;

And sometimes (like right now), I need to make a change to the list, where I insert or remove an element. When I do that, I need to renumber every element in the array after the point where I make the change. So I figured I would dig into the macro editing of VS and make a simple macro which would renumber my array.

- select block of text
- fire off renumber macro
- hooray

So... I need to find the identifier "a", then for every occurrence of a[n], I need to replace the existing n with the right value.

Hm... I may have found my answer already, but if anyone here is a pro and wants to give me the easy solution, I'm listening.
__________________
Peace through fear... since 1947!
icky is offline   Reply With Quote
Old 05-18-2007, 06:41 PM   #2 (permalink)
 
=Sarc='s Avatar
 
Join Date: May 2003
Location: Ottawa, Canada
Posts: 4,633
Re: Visual Studio macros help?

You could set up your array init to be like this:

Code:
a[] = {1,
2,
3,
4,
...,
n};
__________________
JO Guides & Tutorials
Team Element - It's who you game with.
=Sarc= is offline   Reply With Quote
Sponsored links
Old 05-18-2007, 08:02 PM   #3 (permalink)
 
icky's Avatar
 
Join Date: Jul 2005
Location: Ottawa Valley
Posts: 6,154
Re: Visual Studio macros help?

Quote:
Originally Posted by =Sarc= View Post
You could set up your array init to be like this:
True, if I weren't dealing with more than 10k lines of existing code. Many of the arrays are also overlapped because it makes the code easier to understand.

Code:
a[0] = &moo;
a[1] = &bdefn;  //bdefn points to b[]
   b[0] = &tralala;
   b[1] = &omg;
   b[2] = NULL;
a[2] = &fubar;
a[3] = NULL;
This is all really academic now (literally), since I am giving this job away to some lucky dude in China very soon. I just can't stop myself once I get it in my head that I want to solve a stupid little problem with a tool I don't know how to use.

I have almost solved my problem except that my search for ^:b*{:i}\[:z\] isn't giving me the right results. (that's a line starting with 0 or more blanks, then an identifier, then [, then an integer, then ])

gah... it's the weekend... I need to turn this off now...
__________________
Peace through fear... since 1947!
icky is offline   Reply With Quote
Old 05-18-2007, 11:14 PM   #4 (permalink)
 
=Sarc='s Avatar
 
Join Date: May 2003
Location: Ottawa, Canada
Posts: 4,633
Re: Visual Studio macros help?

I don't always try to do a search and replace with a single regex. I usually do several just because it's easier for me to understand and figure out. That might be easier instead of thinking of one regex to complete the entire job.
__________________
JO Guides & Tutorials
Team Element - It's who you game with.
=Sarc= is offline   Reply With Quote
Old 05-18-2007, 11:17 PM   #5 (permalink)
 
icky's Avatar
 
Join Date: Jul 2005
Location: Ottawa Valley
Posts: 6,154
Re: Visual Studio macros help?

Quote:
Originally Posted by =Sarc= View Post
I don't always try to do a search and replace with a single regex. I usually do several just because it's easier for me to understand and figure out. That might be easier instead of thinking of one regex to complete the entire job.
Ya, but this is just one simple find. I just have problems because MS doesn't use the same regex syntax from one place to the next. I tested that string in the normal find/replace and it worked fine.
__________________
Peace through fear... since 1947!
icky is offline   Reply With Quote
Old 05-18-2007, 11:57 PM   #6 (permalink)
 
Iamthefallen's Avatar
 
Join Date: Aug 2005
Location: Columbia, SC
Age: 29
Posts: 935
Re: Visual Studio macros help?

Can't help, but maybe you can find some help here
Iamthefallen is offline   Reply With Quote
Sponsored links
Old 05-19-2007, 12:17 AM   #7 (permalink)
 
icky's Avatar
 
Join Date: Jul 2005
Location: Ottawa Valley
Posts: 6,154
Re: Visual Studio macros help?

Quote:
Originally Posted by Iamthefallen View Post
Can't help, but maybe you can find some help here
Hey, that's cool! I wouldn't come to the TG forums for help if I was willing to HIRE someone though. When I find myself doing monkey work, I always take the opportunity to learn something new. So I'm trying to learn this crazy VB macro system in spite of the lousy documentation and lack of any real online expertise.

I am very close. So close that I might break down and use some of my own time to get it. In a week, I might not be using Visual Studio anymore, but I will have that little bit of knowledge in my pocket to use next time.
__________________
Peace through fear... since 1947!
icky is offline   Reply With Quote
Old 05-19-2007, 12:22 AM   #8 (permalink)
 
Iamthefallen's Avatar
 
Join Date: Aug 2005
Location: Columbia, SC
Age: 29
Posts: 935
Re: Visual Studio macros help?

Yeah I know the feeling, I spent most of my day trying to convince our DB server that CSV files really can have commas inside a quote-delimited field. There are lots of workarounds, but I wanted to make it work my way :-)

VB macros is just one of those things I think goes against all that is right and good in the world.
Iamthefallen is offline   Reply With Quote
Old 05-19-2007, 10:59 AM   #9 (permalink)
 
=Sarc='s Avatar
 
Join Date: May 2003
Location: Ottawa, Canada
Posts: 4,633
Re: Visual Studio macros help?

If the regex system in Visual Studio is weird, you can always open the file in another editor that has regex that does make sense.

You could also try matching all characters up to an equal sign instead of specifically spaces, identifier, square brackets, etc.
__________________
JO Guides & Tutorials
Team Element - It's who you game with.
=Sarc= is offline   Reply With Quote
Old 05-21-2007, 01:13 AM   #10 (permalink)
 
Satertek's Avatar
 
Join Date: Dec 2006
Location: Auburn, Alabama, USA
Age: 22
Posts: 259
Re: Visual Studio macros help?

Use vi, heh. Recently read an article about it doing just what you need.
__________________

Satertek is offline   Reply With Quote
Sponsored links
Old 05-21-2007, 01:30 AM   #11 (permalink)
 
icky's Avatar
 
Join Date: Jul 2005
Location: Ottawa Valley
Posts: 6,154
Re: Visual Studio macros help?

Ya, I figure it would take me about a few minutes to come up with a script in another language, but that's cheating.

Cool vi stuff. I have used it for years but I still don't know half of the functionality. Too little room in my head.
__________________
Peace through fear... since 1947!
icky is offline   Reply With Quote
Old 05-21-2007, 02:00 AM   #12 (permalink)
 
=Sarc='s Avatar
 
Join Date: May 2003
Location: Ottawa, Canada
Posts: 4,633
Re: Visual Studio macros help?

Quote:
Originally Posted by icky View Post
Ya, I figure it would take me about a few minutes to come up with a script in another language, but that's cheating.

Cool vi stuff. I have used it for years but I still don't know half of the functionality. Too little room in my head.
If you can figure it out using another language or any other method, it's not cheating. It's getting the job done. Don't think you have to restrict yourself to certain tools just because you'll learn something. You'll learn something by using the right tools for the job.
__________________
JO Guides & Tutorials
Team Element - It's who you game with.
=Sarc= is offline   Reply With Quote
Old 05-21-2007, 01:46 PM   #13 (permalink)
 
icky's Avatar
 
Join Date: Jul 2005
Location: Ottawa Valley
Posts: 6,154
Re: Visual Studio macros help?

Quote:
Originally Posted by =Sarc= View Post
If you can figure it out using another language or any other method, it's not cheating. It's getting the job done. Don't think you have to restrict yourself to certain tools just because you'll learn something. You'll learn something by using the right tools for the job.
Nah, you aren't getting my way of thinking. If I let myself always use the easiest tool for ME, I wouldn't know half of what I know now. When the opportunity arises for me to expand my toolbox, I almost always do it.
__________________
Peace through fear... since 1947!
icky is offline   Reply With Quote
Old 05-21-2007, 02:39 PM   #14 (permalink)
 
=Sarc='s Avatar
 
Join Date: May 2003
Location: Ottawa, Canada
Posts: 4,633
Re: Visual Studio macros help?

Quote:
Originally Posted by icky View Post
Nah, you aren't getting my way of thinking. If I let myself always use the easiest tool for ME, I wouldn't know half of what I know now. When the opportunity arises for me to expand my toolbox, I almost always do it.
Ah, you're also expanding your toolbox by learning how to identify the easiest tools for the task at hand.

Go for it with the vi editor. Unless... you've got too little room in your head right now.
__________________
JO Guides & Tutorials
Team Element - It's who you game with.
=Sarc= is offline   Reply With Quote
Old 05-28-2007, 01:37 AM   #15 (permalink)
 
marstein's Avatar
 
Join Date: Jul 2005
Location: Half Moon Bay, CA, USA
Age: 42
Posts: 840
Re: Visual Studio macros help?

you could do something like
Code:
i=0;
a[i++] = &something;
a[i++] = &tra;
 ib=0;
 b[ib++] = &xxx
 b[ib++] = null
etc.

Ideally you'd put the initialization data in an external config file.
__________________
Gigabyte P35-DS3R, 2GB, 8800GTS 640MB, Core2Duo E8400
marstein is offline   Reply With Quote
Sponsored links
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


All times are GMT -4. The time now is 06:53 PM.


Powered by vBulletin® Version 3.7.2
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0
©2004-2008 - Tactical Gamer - All Rights Reserved