PerfectScript Journal
 

April 1997: Using Color to Format Your Macros

When writing macros, it is helpful to use color to denote different elements in your code. The colors don't affect macro performance at all;they are strictly for the convenience of the macro writer and anyone who may need to edit the macro at a later date. The small amount of time it takes to "color" sections of code will pay off down the road when you need to edit your macros.

Here's the color scheme I use:

Green for Comments. (Select the comment,then click Format | Font | Text Color | Green)

Redline hard-coded items, such as text,directory paths, or numeric values. (Select the item, choose Format | Font| Redline)

If you ever need to localize your macro for another language (that's a fancy way of saying you need to translate the text in the macro so your German cousin can read it), this helps immensely. I use Redline rather than the text color red because you can search for Redline specifically. (You can search for a specific color code.)

Blue for code that needs adjusting at the last minute, or code you need to check on later. (Select item, choose Format| Font | Text Color | Blue.)

Purple for debugging code, such as BEEP,PROMPT, MESSAGEBOX, or STEP. (Select the item, choose Format | Font | TextColor | Purple).

Once the macro is completed and in good working order, you can quickly find all the purple stuff and delete it. Obviously, if you don't have acolor monitor, or are color blind, colors won't help you much. You could use other attributes such as Large, Extra Large, or italics instead.

Remember that if you have Windows system colors selected in Edit | Preferences | Display | Document, colored text will not appear in color on the screen. But if you do have a color monitor and can differentiate the various colors you choose, you'll be able to quickly find places in your macro you need to pay special attention to (blue).

You'll be able to quickly find all your debug code (purple) and the code that needs checking (blue) and remove or correct it before you distribute your macro.

If you need to change text or paths, you'll be able to quickly find the strings you need to change (red). And you'll be able to quickly find your comments should you need information stored there.

To make changing color fast, I created macros that I have placed on my tool bar. The following changes the color of selected text to green:

Application (WordPerfect; "WordPerfect"; Default; "US")
TextColor(Red: 0; Green: 128; Blue: 0)
SelectMode (State: Off!)           

To change selected text to Redline, use the following macro:

Application (WordPerfect; "WordPerfect"; Default; "US")
AttributeAppearanceOn(Attrib: Redline!)
SelectMode (State: Off!)           
Copyright Notice: The information included in the PerfectScript Journal is
protected by US Copyright. The author grants you the right to use the routines
in your own macros as needed. You may not sell, distribute, or publish them in
any form.
If you choose to use the information here, you do so entirely at your own risk.
No representations are made regarding the fitness of this information for your
particular purpose, or for your ability or inability to use the information. You
are advised to make backups of all relevant files before implementing any suggestion
or technique.
© Copyright 1997 by J. Jeppson.