Click here to Skip to main content
15,910,877 members
Articles / Programming Languages / C++
Article

MacroText

Rate me:
Please Sign up or sign in to vote.
3.00/5 (1 vote)
2 Feb 20021 min read 38.1K   495   9  
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


Written By
Web Developer
Israel Israel
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
-- There are no messages in this forum --