Skip to main content
Skip table of contents

Macros

A macro is a specific instruction (or sequence of instructions) executed within a specific region of a report. Macros within a region are executed each time a row of data is returned to that region:

  • In the detail region, macros are executed for every new row of data returned.
  • Within a sorted region, macros are executed once each time the sort changes.
  • Within a paginated region, macros are executed once each time the page changes.

For example, a macro used in the Detail Region of a Purchase Order Item Listing to return the Item Description is executed for each Purchase Order Item. In the same report, a macro in the Group Footer Region (based on Purchase Order Number) to calculate the Purchase Order Total is executed each time the Purchase Order Number changes.

In another situation, a macro might be used to direct that the amount indicating total revenue appear in one region of the report and the amount indicating total expense appear in another region and that both of these amounts be reset to zero at every new group heading.

There are four different types of statements used within the macro area:

  • Calculations
  • Conditions
  • Declarations
  • Functions

Macros are comprised of statements and may be defined either conditionally or unconditionally.

Use the Macros Editor (Macros tab) in the Report Design window to start creating macros.

Active Macro Language (VBScript)

CDD uses VBScript (Active Macro) language for creating and editing macros. When a report is created, the Macros tab is populated with a script that is divided into sections:

  • The first section is used to place all global variables. Global variables, like User Defined Variables in a report, can be accessed from any other function. The Global variables section corresponds to the Declarations macro in the standard macro language.
  • The next section is the sub for the pseudo-region called Initialize. This function is called first before any other work is done in the report. The function is only called once and corresponds to the Init Macro in the standard CD macro language. Notice the comment in this section reminding the user where to put their statements that belong to this function.
  • Each of the other sections in the script correspond to regions of the report. As new regions are added to the report, the sub (Active Macro function) for that region is added at the end of the script. When you select a region from the list of regions at the top of the macro editor, the sub is found, highlighted, and scrolled into view.

Formatting Preferences

On the Macro preference page (Edit > Preferences > Macros tab), you can specify whether you would like syntax coloring enabled by default and whether a selection margin with (or without) line numbers should be shown. The selection margin provides a simple method to select blocks of text for copying or moving.

Finding Text

To find an occurrence of a string in the text editor, press Ctrl-F while within the editor. By default, the search is not case-sensitive, and the search direction is toward the end of the file from the current location of the cursor. If the pattern is not found, the search will wrap around and begin from the top.

Replacing Text

To replace one or more occurrences of a text string, press Ctrl-H while within the editor. The find and replace dialog is displayed. You can replace all found occurrences without prompting by pressing the Replace All. By pressing the Find Next button, you can skip one or more occurrence of the find string.

Bookmarks

When editing large macros, it is helpful to be able to jump from one location to another with the press of the button; bookmarks provide this capability.

To set a bookmark, you press Ctrl-F2 and a small blue rectangle will appear in the selection margin. Move to the next location that you would like to place a bookmark and press Ctrl-F2 again. You may now jump between the two bookmarks by pressing F2.

To clear a bookmark, place the cursor on the same line as the bookmark and press Ctrl-F2.

To clear all bookmarks, press Ctrl+Shift+F2.

 

JavaScript errors detected

Please note, these errors can depend on your browser setup.

If this problem persists, please contact our support.