Writing Code with Macros

bpayne111

Junior Contributor
Joined
Feb 28, 2003
Messages
325
Location
BFE
Just about everytime i create a new class i use the same 3 regions, Declarations, Properties, and Methods. I tried creating a macro to do this for me by letting it record my keystrokes. It worked ok but sometimes it screwed up and put stuff where it wasn't supposed to be. I know you can write macros using code... So how would i make a marco to do these regions for me using code?
Thanks
Brandon
 
You could modify the file at:

C:\Program Files\Microsoft Visual Studio .NET\Vb7\VBWizards\Class\Templates\1033\Class.vb

which is the template for the New Class item, and change that. You can also add your own item templates, but it is a bit more work. There's probably some info in the MSDN about that.
 
You can also modify the template forms. There might be a way to add new templates, but I haven't looked.

Using C# as an example, I changed the following file:
C:\Program Files\Microsoft Visual Studio .NET 2003\VC#\VC#Wizards\CSharpAddWinFormWiz\Templates\1033\NewWinForm.cs

Whenever I add a new form it uses this as the file. It does some fancy replacing so don't modify it too much. I removed most of the built in comments and added some regions, much like you're asking for. Plus a few more using statement (Imports in VB) that I use all the time.

-Nerseus
 
wow that's really cool, that would be much better than a macro any day...thanks for the good (and fast) response
 
WOW that is cool i just did it... so will this work if i say add a button to a form and copy the code? i'd like to hear some more details of how you guys used this to your advantage
 
For something like that you should look into using Form Inheritance. It's sort of limited, but can be useful for making things like dialog boxes and such.
 
yea i know about inheritance but then i can't edit the controls the way i want... if i had just one exit button on a form at load that i could play with (size and etc..) then i'd be happy
 
That sounds like it would be quite feasible. In fact, I may look into this myself and write an article about it. I haven't written anything for Tutors Corner in awhile.
 
let me know if you do.. i'd like to read it.
thanks guys
(ohh and yes i saved a copy before i saw your message ;))
 
Back
Top