Previous Document Next Document

Getting started with macros : Using the Macro Editor : Using the Code window

Using the Code window

The Code window is where you spend most of your time when working on macros. A standard code editor in the style of Microsoft Visual Studio, the Code window lets you do the following:


If you are already familiar with any of the Microsoft Visual Studio editors, the Code window will be entirely familiar to you.

The Code window

To display the Code window, do one of the following:

Click View } Code.
Press F7.
Formatting code automatically

The Macro Editor formats code automatically for you. Even the capitalization of keywords, functions, subroutines, and variables is taken care of by the Macro Editor, irrespective of what you type. You cannot custom-format code, although you can set the indentation for each line, as well as the placing of custom line breaks.

If you use the returned value when calling a function, the parentheses around the parameters are mandatory (just as in most modern programming languages):

a = fooFunc (b, c)

However, if the returned value from a function call is being discarded, or if you are calling a subroutine, the parentheses must be left out (unlike in most other languages):

barFunc d, e
fooBarSub f

If you prefer always to see the parentheses, use the Call keyword before the function call or subroutine call:

Call barFunc (d, e)
Call fooBarSub (f)
Coloring syntax automatically

As you develop code in the Code window, the Macro Editor colors each word according to its classification.

Word color
Automation keyword or programming statement
All other text

The Code window also uses the following colorization techniques:

Colorization technique
Red text
Line of code containing errors
White text on blue background
Selected text
Text highlighted in yellow
Line where execution is paused for debugging
White text on red background and red dot in the left margin
Breakpoint set for debugging purposes
For more information, see Setting breakpoints.
Blue dot in the left margin
Bookmark set in the code

These syntax-colorization techniques make the code much easier to read.

Syntax coloring and highlighting

Breakpoints and bookmarks are lost when you quit the application.

The Macro Editor lets you modify the default colors for syntax highlighting. Click Tools } Options, and choose your settings on the Editor Format page.
Checking syntax automatically

Every time you move the cursor out of a line of code, the Macro Editor checks the syntax of the code in that line; if an error is found, the line is colored red and a pop-up warning is displayed. This real-time checking is useful (particularly when you are learning to program macros) because it indicates many possible errors in the code without having you run the code.

The Macro Editor lets you disable pop-up warnings. Click Tools } Options, click the Editor tab, and then disable the Auto Syntax Check check box. Although the Macro Editor still checks the syntax and colors erroneous lines red, it stops displaying a warning when you paste text from another line of code.
Jumping to definitions

The Macro Editor lets you jump directly to the definition of a variable, function, or object.

Desired definition
Right-click the variable in the Code window, and then click Definition.
The definition of the variable in the code
Right-click the function in the Code window, and then click Definition.
The definition of the function in the code
Right-click the object in the Code window, and then click Definition.
The definition of the object in the Object Browser

To return to where you requested the definition, right-click anywhere in the Code window, and then click Last Position.
Using contextual pop-up lists for automatic completion

The Macro Editor adds the functions you write and the variables you define to an internal list that contains all built-in keywords and enumerated values. As you type, the Macro Editor displays a contextual list of words that are valid candidates for insertion at the current position. This auto-completion feature makes code development quicker and more convenient.

An auto-completion pop-up list

If you type the first few characters of the word you want to use, the pop-up list advances to the nearest candidate that matches those characters. Select the desired word, and then do one of the following:

type the character to follow the word (typically a space, line feed, parenthesis, period, or comma)
enter only the word by pressing Tab or Ctrl + Enter

To force the pop-up menu display, press Ctrl + Spacebar; the menu scrolls to the word that most closely matches the characters that you have typed so far. This technique is particularly useful for filling parameter lists when calling a function or subroutine. If there is only one exact match, the Macro Editor inserts the word without popping up the list; to display the pop-up list for the selected keyword at any time without auto-filling it, press Ctrl + J.

Previous Document Next Document Back to Top

Copyright 2013 Corel Corporation. All rights reserved.