Getting started with macros : Using the Macro Editor : 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.
|
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) |
As you develop code in the Code window, the Macro Editor colors each word according to its classification.
Word color
|
Classification
|
---|---|
Blue
|
Automation keyword or programming statement
|
Green
|
Comment
|
Black
|
All other text
|
The Code window also uses the following colorization techniques:
Colorization technique
|
Classification
|
---|---|
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.
|
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 jump directly to the definition of a variable, function, or object.
• |
To return to where you requested the definition, right-click anywhere in the Code window, and then
click Last Position.
|
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
|
Copyright 2013 Corel Corporation. All rights reserved.