Comment helper macros (3)

At the company where I work (www.schlaps-automation.de), we are still using the Microsoft C/C++ 7.0 for programming 16 Bit Windows applications (oh yes, there are customers who want programs for Windows 3.x). We are also using the Micosoft Programmers Workbench (PWB) as the IDE for this compiler. Since you can enhance the PWB's functionality with special extension libraries, several years ago we wrote some useful helpers for the PWB. Time marches on and if you have to program today for Win95/98/NT, life is easier if you are using Visual C++ and Visual Studio. You can customize Visual Studio in many ways. However, I missed some of the functions that I had used PWB. Therefore, I decided to implement them as Visual Studio macros. This article contains three (3) of these macros.

1) I like the C comment style where the comments are vertically aligned to the right of the source code.


for(i=0;i<1000;i++)            // search loop
{
 if(c[i]==0) break;            // empty space found ? done
 if(c[i]==1) c[i]=2;           // replace 1 with 2
}
If you want to use this comment style, you spend a lot of time placing the comments so that they align just right. And if you change one line of code, you always have to re-adjust the comment so that it still aligns properly.

Therefore, my first macro works by executing it while the cursor is on the line where the comment will be added or adjusted.

You can even select more than one line of source code when executing the macro. Every line will get a new comment sign or the existing comments will be re-adjusted (if needed).

The biggest advantage this macro has over similar macros presented on Codeguru, is that it will work with lines of code that already contain comments.

2) The second macro does just the opposite: it removes single-line comments (not only the comment signs, but also all text after the comment characters (//) If you are using the "auto-comment" feature of the Visual Studio and you are looking for an easy way to remove some of the useless comments (or if you want to remove your own useless comments :), just place the cursor on the offending line(s) of code and execute this macro

3) I HATE TABS! The first thing I did in Visual Studio was to disable the tab-chars. It4s a lot easier to navigate in the source when spaces are used instead.

But if you are using the Wizard stuff, tabs will be inserted in the generated code. So my last macro simply removes all tabs from the source code and replaces them with spaces.

NOTE: It should be noted that my "comment" macros also hate tabs. Therefore, you will need to run this macro first before using my comment macros.

Date Last Updated: February 3, 1999



Downloads

Comments

  • Improvements

    Posted by Pelle1911 on 06/01/2005 06:16am

    Hi there, I looked at your macros and modified them. Actually I do believe the the new version is superior to the old version and would like to share that stuff. However, the base of it is still this work so that I don't want to post it as my own work. Any comments? Regards, C.

    Reply
  • You are very penible, I think all programmers

    Posted by Legacy on 10/11/1999 12:00am

    Originally posted by: pat

    Reply
  • Simple Untab selection before comments

    Posted by Legacy on 03/16/1999 12:00am

    Originally posted by: Oscar

    Just put this as a first line after the the sub comment

    ActiveDocument.Selection.Untabify

    and everything will be fine

    oscar

    Reply
Leave a Comment
  • Your email address will not be published. All fields are required.

Top White Papers and Webcasts

  • U.S. companies are desperately trying to recruit and hire skilled software engineers and developers, but there is simply not enough quality talent to go around. Tiempo Development is a nearshore software development company. Our headquarters are in AZ, but we are a pioneer and leader in outsourcing to Mexico, based on our three software development centers there. We have a proven process and we are experts at providing our customers with powerful solutions. We transform ideas into reality.

  • On-demand Event Event Date: August 27, 2015 With the cloud enabling companies to spin up servers and stand up data stores more quickly, mobile apps can be created faster, reducing the time-to-value. But three major obstacles stand in the way for many organizations: The backlog of app project requests confronting every enterprise regardless of their internal app development capabilities Finding and employing better, faster tools to speed and simplify the process of developing those apps. The emergence of …

Most Popular Programming Stories

More for Developers

RSS Feeds

Thanks for your registration, follow us on our social networks to keep up-to-date