Click here to Skip to main content
Licence 
First Posted 2 Feb 2002
Views 31,873
Bookmarked 9 times

MacroText

By | 2 Feb 2002 | Article
The application turns a regular code copied from a file to a macro text - A text you can paste to a VC++ macro to create new macros swiftly.

Introduction

When you want to create a macro that will serve as a sophisticated template of your code, you usually need to do something like this:

ActiveDocument.Selection = _ 
"list<" + CType + "*>::const_iterator i, iEnd = " + CName + ".end();"
ActiveDocument.Selection.NewLine
ActiveDocument.Selection.NewLine
ActiveDocument.Selection = "for(i = " + CName + ".begin(); i != iEnd; i++)"
ActiveDocument.Selection.NewLine
ActiveDocument.Selection = "{"
ActiveDocument.Selection.NewLine
ActiveDocument.Selection = "}"
ActiveDocument.Selection.NewLine

This is terrible to write and even more terrible to understand and fix, especially when you have to do long code macro. Better looking way would be to do this:

ActiveDocument.Selection = _
"list<" + CType + "*>::const_iterator i, iEnd = " + _ 
CName + ".end();" & vbLf & vbLf & vbLf & _
"for(i = " + CName + ".begin(); i != iEnd; i++)" & vbLf & vbLf & _
"{" & vbLf & vbLf & _
"}" & vbLf & vbLf & _

However, as comfortable as it is to look upon, converting regular text to this form does take time.

Automation

This is where the little MacroText application becomes useful. Let's say I want to convert a code - template list loop - to a macro template:

Now all I need to do is to press the "Convert" button and walla:

Now all that is left to do is to copy the converted text to a macro, add the appropriate msgboxes to gather info, for example, let's say they are DataType and ListName. So we do the following from VC++:

Replace int with & DataType &. Replace m_List with & ListName &.

And here is the result:

"list<" & DataType & ">::const_iterator i, iEnd = " & _ 
ListName & ".end();" & vbLf & "" & vbLf & _
"for(i = " & ListName & ".begin(); i != iEnd; i++)" & vbLf & _
"{" & vbLf & _
"}"

For whom

The program is especially useful for creating template macros - The macros in which you have to repeat the same type of code over and over with slight changes. While some add-ins come with "templates" ability, I found them all lacking, either in execution and in comfort of use, compared to the macros I can make with MacroText.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

About the Author

Vitaly Belman

Web Developer

Israel Israel

Member



Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board. (secure sign-in)
 
Search this forum  
 FAQ
    Noise  Layout  Per page   
  Refresh
-- There are no messages in this forum --
Permalink | Advertise | Privacy | Mobile
Web02 | 2.5.120517.1 | Last Updated 3 Feb 2002
Article Copyright 2002 by Vitaly Belman
Everything else Copyright © CodeProject, 1999-2012
Terms of Use
Layout: fixed | fluid