Chapter 9

See Graphic

Macro Examples






Macro Examples

This section presents four example macros. The example macros demonstrate some common techniques used in advanced macros. Some of these techniques include calling subroutines, creating callback functions, and using Dynamic Data Exchange (DDE). Each macro is shown with line numbers and followed by a table describing the function(s) of each line of code. The following table gives a brief description of each macro.

Three of the examples, ASSERT.WCM, CALLBACK.WCM, and CB-SCBAR.WCM demonstrate advanced macro techniques but have no practical application. The other example, CALENDAR.WCM, demonstrates additional techniques through practical application. To copy the example macros, copy them to the Clipboard from the Macro Programming online Help. Then paste the example macro to a blank Corel WordPerfect document and save it with a .WCM extension. You can then edit or play the macro.

For example, to access the online Help in Corel WordPerfect, click Help > Help Topics > Contents double-click Macros click Macro Programming.

Macro

Description

ASSERT.WCM Displays a menu and creates Cancel, Error, and Not Found conditions.
CALLBACK.WCM Creates a callback function that responds to system menu box options and various dialog controls.
CB_SCBAR.WCM Creates a callback function that responds to the position of a scroll bar thumb.
CALENDAR.WCM Uses DDE to launch Novell GroupWise 4.1 and open the day calendar.

For a callback function example that responds to list item selections, see the example under PerfectScript DialogShow command.


ASSERT.WCM

ASSERT.WCM uses Menu to display a list of options; Assert to create a Cancel, Error, or Not Found condition; and OnCancel, OnError, or OnNotFound to execute a subroutine. It also uses MessageBox to display messages and Go to create user-defined loops.

1 // Name: ASSERT.WCM
2 // Directory: C:\OFFICE8\MACROS\...
3 // Description: Demonstrate Assert command
4 APPLICATION(WP; "WordPerfect"; Default; "EN")
5 CALL(AssertConditions) 
6 CALL(DisplayMenu)
7 CALL(QuitMacro)
8  //*********************************************************
9  //MAIN LABEL STATEMENTS
10 //*********************************************************
11 LABEL(AssertConditions)
12  ONCANCEL(Conditions)
13  ONERROR(Conditions)
14  ONNOTFOUND(Conditions)
15  vCondition := "Turn conditions Off!"
16  RETURN
17 LABEL(DisplayMenu)
18  MENU(vChoice; Digit!; ; ; {"CancelCondition!"; "ErrorCondition!"; "NotFoundCondition!";
     vCondition; "Quit"})
19  SWITCH(vChoice)
20   CASEOF 1: ASSERT(CancelCondition!)
21   CASEOF 2: ASSERT(ErrorCondition!)
22   CASEOF 3: ASSERT(NotFoundCondition!)
23   CASEOF 4: IF(vCondition = "Turn conditions Off!")
24     GO(TurnConditionsOff)
25    Else
26     GO(TurnConditionsOn)
27    ENDIF 
28   CASEOF 5: GO(QuitMacro)
29   DEFAULT: Conditions
30  ENDSWITCH
31  RETURN
32 LABEL(QuitMacro)
33  vMessage := "You selected 5, or you selected 1, 2, or 3 with all conditions Off!"
34  MESSAGEBOX(vStatus; "Condition Status"; vMessage; RetryCancel! | IconInformation! |
      DefButton2!)
35  IF(vStatus = MessageBox.RetryButton!)
36   GO(DisplayMenu)
37  Else
38   QUIT
39  ENDIF
40 //*********************************************************
41 //SECONDARY LABEL STATEMENTS 
42 //*********************************************************
43 LABEL(Conditions)
44  SWITCH(ErrorNumber)
45   CASEOF ErrorNumber.CancelConditionAsserted!: vMessage := "^0"
46   CASEOF ErrorNumber.ErrorConditionAsserted!: vMessage := "^1"
47   CASEOF ErrorNumber.NotFoundConditionAsserted!: vMessage := "^2"
48   DEFAULT: vMessage := "^3"
49  ENDSWITCH
50  MESSAGEBOX(vStatus; "Condition Status"; vMessage; Ok! | IconInformation! | HasParameters!;
      {"You selected 1 with CANCEL(On!)"; "You selected 2 with ERROR(On!)"; "You selected 3 with
      NOTFOUND(On!)"; "Menu item not chosen"})
51  GO(DisplayMenu)
52 LABEL(TurnConditionsOn)
53  CANCEL(On!)
54  ERROR(On!)
55  NOTFOUND(On!)
56  vCondition := "Turn conditions Off!"
57  GO(DisplayMenu)
58 LABEL(TurnConditionsOff)
59  CANCEL(Off!)
60  ERROR(Off!)
61  NOTFOUND(Off!)
62  vCondition := "Turn conditions On!"
63  GO(DisplayMenu)
Lines

Description

Lines 1-3 Comments about the macro.
Line 2 Macros are generally saved to the application's macros directory.
Line 4 Corel WordPerfect identified as the default application.
Line 5 Call LABEL(AssertConditions), which identifies a LABEL subroutine to call when there is a Cancel, Error, or Not Found condition (lines 12-14).
Line 6 Call LABEL(DisplayMenu) after LABEL(AssertConditions) returns (line 16). LABEL(DisplayMenu) displays a five-option menu (line 18).
Line 7 Call LABEL(QuitMacro) after LABEL(DisplayMenu) returns (line 31). LABEL(QuitMacro) displays a message box where the user can end the macro or redisplay the menu (lines 32-39).
Lines 8-10 Comments identify LABELs that correspond to the opening CALL statements (lines 5-7).
Lines 11-16 LABEL(AssertConditions) identifies a LABEL to execute when a Cancel, Error, or Not Found condition occurs.
Line 12 Execute LABEL(Conditions) when a Cancel condition occurs (line 43).
Line 13 Execute LABEL(Conditions) when an Error condition occurs (line 43).
Line 14 Execute LABEL(Conditions) when a Not Found condition occurs (line 43).
Line 15 Assignment operator assigns a character string to a variable named vCondition, which is menu item 4 the first time the menu is displayed (line 18). The default condition for CANCEL, ERROR, and NOTFOUND is On!.
Line 16 RETURN statement directs macro execution to CALL(DisplayMenu) (line 6).
Lines 17-31 LABEL displays a five-option menu and asserts a Cancel, Error, or Not Found condition depending on a menu choice.
Line 18 MENU displays a numbered (Digit!) list of five items. The number the user chooses is assigned to vChoice. Omitting the third and fourth parameters centers the menu on the screen.
Line 19 SWITCH initiates an action, depending on the value of vChoice, which contains the number of the chosen menu item.
Line 20 If 1 is selected, assert a Cancel condition. The macro assigns 1 to the variable ErrorNumber (see PerfectScript Assert command). LABEL(Condition) is automatically called (lines 12 and 45).
Line 21 If 2 is selected, assert an Error condition. The macro assigns 2 to the variable ErrorNumber (see PerfectScript Assert command). LABEL(Condition) is automatically called (lines 13 and 46).
Line 22 If 3 is selected, assert a Not Found condition. The macro assigns 7 to the variable ErrorNumber (see PerfectScript Assert command). LABEL(NotFound) is automatically called (line 14 and line 47).
Lines 23-27 If 4 is selected, toggle CANCEL, ERROR, and NOTFOUND conditions by calling LABEL(TurnConditionsOn) (lines 52-57) or LABEL(TurnConditionsOff) (lines 58-63). The label called depends on the contents of variable vCondition (lines 15, 56, and 62). Update the description of menu item 4.
Line 28 If 5 is selected, end (quit) macro.
Line 29 If another key is pressed, such as Esc, LABEL(Condition) executes. Notice that the subroutine name executes the subroutine. See Subroutine Name in Chapter 5: Conditional, Loop, and Calling Statements.
Line 30 ENDSWITCH closes SWITCH statement (line 19).
Line 31 RETURN statement directs macro execution to CALL(QuitMacro).
Lines 32-39 LABEL(QuitMacro) displays a message box with an option to end the macro or redisplay the menu.
Line 33 Assignment operator assigns character string "You selected 5, or you selected 1, 2, or 3 with all conditions Off!" to variable vMessage (line 34).
Line 34 MESSAGEBOX displays a message box with an information icon and Retry and Cancel buttons. If Retry is chosen, 4 is assigned to variable vStatus, or 2 is assigned to vStatus if Cancel is chosen.
Lines 35-36 If variable vStatus equals MessageBox.RetryButton! (line 34), GO sends macro execution to LABEL(DisplayMenu), which redisplays the menu.
Lines 37-38 If vStatus is any value except 4 (Else), end the macro (QUIT).
Line 39 ENDIF closes IF statement (line 35).
Lines 40-42 Comments identify secondary LABELs or LABELs called from another LABEL (see lines 12-14, 24, and 26).
Lines 43-51 Execute LABEL(Conditions) when the user chooses 1, 2, or 3 (lines 20-22 and 12-14).
Line 44 SWITCH initiates an action, depending on the value of the variable ErrorNumber (lines 20, 21, 22) (see PerfectScript Assert command).
Line 45 If ErrorNumber equals ErrorNumber.CancelConditionAsserted!, assign "^1" to vMessage (see line 50).
Line 46 If ErrorNumber equals ErrorNumber.ErrorConditionAsserted!, assign "^2" to vMessage (see line 50).
Line 47 If ErrorNumber equals ErrorNumber.NotFoundContitionAsserted!, assign "^3" to vMessage (line 50).
Line 48 If ErrorNumber contains any other value, assign "^4" to vMessage (line 50).
Line 49 ENDSWITCH closes SWITCH statement (line 44).
Line 50 MESSAGEBOX displays a message box with an information icon and OK button. It uses the HasParameters! style, followed by four Message parameter options. A caret (^) followed by a number in the Message parameter inserts the corresponding ParameterData message (one of the four message options) in its place (lines 45-48). Numbering begins with 0. See PerfectScript MessageBox command.
Line 51 GO creates a loop by sending macro execution to LABEL(DisplayMenu), which redisplays the menu.
Lines 52-55 LABEL(TurnConditionsOn) turns on CANCEL, ERROR, and NOTFOUND conditions after LABEL(TurnConditionsOff) is executed.
Line 56 Assigns character string "Turn conditions Off!" to variable vCondition, which is displayed as menu item 4 (line 18).
Line 57 GO creates a loop by sending macro execution to LABEL(DisplayMenu), which redisplays the menu.
Lines 58-61 LABEL(TurnConditionsOff) turns off CANCEL, ERROR, and NOTFOUND conditions after the macro first starts or LABEL(TurnConditionsOn) is executed.
Line 62 Assigns character string "Turn conditions On!" to variable vCondition, which is displayed as menu item 4 (line 18).
Line 63 GO statement creates a loop by sending macro execution to LABEL(DisplayMenu), which redisplays the menu.

CALLBACK.WCM

CALLBACK.WCM creates a callback function that responds to system menu box options, check boxes, radio buttons, hot spots, and push buttons.

1 // Name: CALLBACK.WCM
2 // Directory: C:\OFFICE8\MACROS\...
3 // Description: Callback function displays a message when a user chooses 
a dialog box control
4 APPLICATION(WP; "WordPerfect"; Default; "EN")
5 //*********************************************************
6 // MAIN CALL STATEMENTS
7 //*********************************************************
8 CALL(InitializeVariables)
9 CALL(CreateDialog)
10 CALL(DisplayMainDialog)
11 CALL(StartMessageLoop)
12 CALL(QuitMacro)
13 //*********************************************************
14 // MAIN LABEL STATEMENTS
15 //*********************************************************
16 LABEL(InitializeVariables)
17  WM_SYSCOMMAND := 274
18  WM_COMMAND := 273
19  vCheck := 0
20  vRadio := 0
21  vLoop := "Yes"
22  RETURN
23 LABEL(CreateDialog
24  DIALOGDEFINE(1000; 50; 50; 210; 175; 1+2+16; "Callback Function")
25  DIALOGADDCHECKBOX(1000; 101; 10; 10; 50; 10; "Checkbox"; vCheck)
26  DIALOGADDRADIOBUTTON(1000; 102; 10; 30; 60; 10;"Radio button"; vRadio)
27  DIALOGADDHOTSPOT(1000; 103; 90; 10; 50; 50; 1)
28  DIALOGADDFRAME(1000; 104; 90; 10; 50; 50; 5)
29  DIALOGADDTEXT(1000; 105; 150; 30; 50; 15; 1; "Hot spot")
30  vText1 := "Choose Close from the system menu, double-click"
31  vText2 := "the system menu box, or press Alt+F4."
32  DIALOGADDTEXT(1000; 106; 20; 95; 190; 15; 1; vText1)
33  DIALOGADDTEXT(1000; 107; 20; 105; 170; 15; 1; vText2)
34  DIALOGADDGROUPBOX(1000; 109; 10; 75; 185; 50; "System commands")
35  RETURN
36 LABEL(DisplayMainDialog)
37  DIALOGSHOW (1000; 1; MsgLoop)
38  RETURN
39 LABEL(StartMessageLoop)
40  WHILE(vLoop = "Yes")
41  ENDWHILE
42  RETURN
43 LABEL(QuitMacro)
44  DIALOGDESTROY(1000)
45  QUIT
46 //*********************************************************
47 // CALLBACK FUNCTION
48 //*********************************************************
49 LABEL(MsgLoop)
50  SWITCH(MsgLoop[3])
51   CASEOF 101:
52    DIALOGDISMISS(1000; "OKBttn")
53    MESSAGEBOX(vStatus; "Check Box"; "Check boxes display options. Choose OK to hide the
        message box and return to the main dialog box."; OK! | IconInformation!)
54    DIALOGSHOW (1000;1; MsgLoop)
55   CASEOF 102:
56    MESSAGEBOX(vStatus; "Radio Button"; "Radio buttons display mutually-exclusive options.
        Choose OK to hide the message box and return to the main dialog box."; OK! |
        IconInformation!)
57   CASEOF 103:
58    MESSAGEBOX(vStatus; "Hot Spot"; "A hot spot was created over a filled frame. You can
        also create a hot spot over an icon. Choose OK to hide the message box and return to the
        main dialog box."; OK! | IconInformation!)
59   CASEOF "OKBttn":
60    MESSAGEBOX(vStatus; "OK Button"; "You chose the OK button on the main dialog box.
        Choose OK to hide the message box and return to the main dialog box."; OK! |
        IconInformation!)
61   CASEOF "CancelBttn":
62    MESSAGEBOX(vStatus; "Cancel Button"; "Choosing Cancel assigns ""No"" to variable<
        vLoop, which ends the loop and the macro."; OK! | IconExclamation!)
63    vLoop := "No"
64  ENDSWITCH
65  IF(MsgLoop[5] = WM_SYSCOMMAND)
66   MESSAGEBOX(vStatus; "System Command"; "After you choose OK, the main dialog box will
       disappear and then reappear after one second."; OK! | IconInformation!)
67   DIALOGDISMISS(1000; "OKBttn")
68   WAIT(10)
69   DIALOGSHOW(1000; 1; MsgLoop)
70  ENDIF
71  RETURN
Lines

Description

Lines 1-3 Comments about the macro.
Line 2 Macros are generally saved to the default macros directory.
Line 4 Corel WordPerfect identified as the default application.
Lines 5-7 Comments identify the opening CALL statements that outline and define the macro's basic operations.
Line 8 Call LABEL(InitializeVariables), which initializes all variables (lines 16-22). A run-time error occurs if you reference a variable that has not been assigned a value. See PerfectScript VarErrChk command.
Line 9 Call LABEL(CreateDialog) after LABEL(InitializeVariables) returns. LABEL(CreateDialog) creates a dialog box in memory (lines 23-35). It does not display the dialog box.
Line 10 Call LABEL(DisplayMainDialog) after LABEL(CreateDialog) returns. LABEL(DisplayMainDialog) displays the dialog box and identifies a callback function. See PerfectScript DialogShow command.
Line 11 Call LABEL(StartMessageLoop) after LABEL(DisplayDialog) returns. LABEL(StartMessageLoop) starts a message loop that suspends the dialog box for callback functions (lines 49-71).
Line 12 CALL LABEL(QuitMacro) after LABEL(StartMessageLoop) returns. LABEL(QuitMacro) removes the dialog box from memory and ends the macro.
Lines 13-15 Comments identify LABELs that correspond to the opening CALL statements (lines 8-12).
Lines 16-22 LABEL(InitializeVariables) initializes all variables
Lines 17-18 Initialize variables to contain Windows message numbers. Using variables makes the macro easier to read. The variable names are user defined, but match the Windows message names. See PerfectScript DialogShow command.
Lines 19-20 Initialize check box and radio button variables (lines 25, 26).
Line 21 Initialize the loop variable. vLoop is later assigned a new value to end the message loop (line 63), which sends macro execution to CALL(QuitMacro).
Line 22 RETURN sends macro execution to CALL(CreateDialog).
Lines 23-35 LABEL(CreateDialog) creates a dialog box in memory.
Lines 25-27 Control parameter values are sent as messages to the callback function (52-63).
Line 35 RETURN sends macro execution to CALL(DisplayMainDialog).
Lines 36-38 LABEL(DisplayMainDialog) displays the dialog box and identifies the callback function MsgLoop. RETURN sends macro execution to CALL(StartMessageLoop).
Lines 39-42 LABEL(StartMessageLoop) starts the message loop that suspends the dialog box for callback functions (lines 49-71). RETURN sends macro execution to CALL(QuitMacro).
Lines 43-45 LABEL(QuitMacro) removes the dialog box from memory and ends the macro.
Lines 46-48 Comments identify the callback function.
Lines 49-71 Callback function MsgLoop responds to five Control parameter messages and one system command message. See PerfectScript DialogShow command.
Line 50 SWITCH tests the third element of the callback function array. See PerfectScript DialogShow command.
Lines 51-63 Array element MsgLoop[3] contains the Control parameter value of the control that calls the callback function. A message box describes the control. In this macro, Cancel is the only button that can dismiss the dialog box.
Line 52 DIALOGDISMISS hides the dialog box while the message box is displayed (line 54).
Line 54 DIALOGSHOW redisplays the dialog box after the message box is dismissed (line 52).
Line 64 ENDSWITCH closes the SWITCH statement (line 50).
Lines 65-70 A WM_SYSCOMMAND message is received when the user chooses Close from the system menu box, double-clicks the system menu box, or presses Alt+F4.
Lines 67-69 DIALOGDISMISS hides the dialog box after the message box is dismissed. WAIT(10) pauses the macro for one second. DIALOGSHOW redisplays the dialog box.
Line 70 ENDIF closes the IF statement (line 65).
Line 71 RETURN sends macro execution to the message loop (lines 39-42).

CB_SCBAR.WCM

CB_SCBAR.WCM creates a callback function that responds to Windows WM_VSCROLL, WM_ACTIVATE, and WM_SYSCOMMAND messages. It uses DIALOGADDSCROLLBAR to display a list item.

1 // Name: CB_SCBAR.WCM
2 // Directory: C:\OFFICE8\MACROS\...
3 // Description: Use DIALOGADDSCROLLBAR and a callback function
4 APPLICATION(WP; WordPerfect; Default; "EN")
5 //*********************************************************
6 // MAIN CALL STATEMENTS 
7 //*********************************************************
8 CALL(InitializeVariables)
9 CALL(CreateDlg)
10 CALL(DisplayDlg)
11 CALL(StartMessageLoop)
12 CALL(QuitMacro)
13 //*********************************************************
14 // MAIN LABEL STATEMENTS
15 //*********************************************************
16 LABEL(InitializeVariables)
17  SB_LINEUP := 0
18  SB_LINEDOWN := 1
19  SB_PAGEUP := 2
20  SB_PAGEDOWN := 3
21  SB_THUMBPOSITION := 4
22  SB_THUMBTRACK := 5
23  SB_TOP := 6
24  SB_BOTTOM := 7
25  SB_ENDSCROLL := 8
26  vOldPos := 10
27  y := 1
28  WM_SYSCOMMAND:= 274
29  WM_VSCROLL := 277
30  WM_ACTIVATE := 6
31  vLoop := 1
32  DECLARE List[10]
33  vElement := 1
34  FOREACH(vFruit; {"Apples"; "Oranges"; "Papaya"; "Grapes"; "Bananas"; 
      "Pears"; "Watermelon"; "Apricots"; "Peaches"; "Plums"})
35   List[vElement] := vFruit
36   vElement := vElement + 1
37  ENDFOR
38  RETURN
39 LABEL(CreateDlg)
40  DIALOGDEFINE(1000; 50; 50; 155; 160; 16; "Scroll Bar Callback Function")
41  DIALOGADDSCROLLBAR(1000; "Scroll"; 135; 10; 0; 100; 2 + 8;BarPos; 1; 10)
42  FORNEXT(yPos; 10; 100; 10)
43   DIALOGADDTEXT(1000; 0; 10; yPos; 40; 10; 2; List[yPos / 10])
44  ENDFOR
45  DIALOGADDTEXT(1000; 0; 60; 10; 40; 10; 1; "Apples")
46  DIALOGADDTEXT(1000; 0; 50; yPos + 15; 70; 10; 1; "Thumb Position 1")
47  RETURN
48 LABEL(DisplayDlg)
49  DIALOGSHOW (1000; 121; MsgLoop) // callback function = MsgLoop
50  RETURN
51 LABEL (StartMessageLoop)
52  WHILE(vLoop = 1) // message loop
53  ENDWHILE
54  RETURN
55 LABEL(QuitMacro)
56  DIALOGDESTROY(1000)
57  QUIT
58 //*********************************************************
59 // CALLBACK FUNCTION
60 //*********************************************************
61 LABEL(MsgLoop)
62  SWITCH(MsgLoop[5])
63   CASEOF WM_SYSCOMMAND:
64    GO(QuitMacro)
65   CASEOF WM_VSCROLL:
66    CALL(ScrollCtrl)
67   CASEOF WM_ACTIVATE:
68    CALL(MsgBox)
69  ENDSWITCH
70  SWITCH(MsgLoop[3])
71   CASEOF "CancelBttn":
72    GO(QuitMacro)
73  ENDSWITCH
74  RETURN
75 LABEL(ScrollCtrl)
76  SWITCH(MsgLoop[6])
77   CASEOF SB_LINEUP:
78    CALL(LineUp)
79   CASEOF SB_LINEDOWN:
80    CALL(LineDown)
81   CASEOF SB_PAGEUP:
82    CALL(PageUp)
83   CASEOF SB_PAGEDOWN:
84    CALL(PageDown)
85   CASEOF SB_THUMBPOSITION:
86    CALL(Thumb)
87   //CASEOF SB_THUMBTRACK:
88    //CALL(Thumb)
89   CASEOF SB_TOP:
90    CALL(PageUp)
91   CASEOF SB_BOTTOM:
92    CALL(PageDown)
93   CASEOF SB_ENDSCROLL:
94    DIALOGADDTEXT(1000; 0; 107; 125; 10; 10; 1; y)
95  ENDSWITCH
96  RETURN
97 LABEL(Thumb)
98  y := MsgLoop[7]
99  y := y & 65535
100  CALL(TypeFruit)
101  RETURN
102 LABEL(LineUp)
103  IF(NOT(y = 1))
104   y := y - 1
105   CALL(TypeFruit)
106  Else
107   BEEP
108  ENDIF
109  RETURN
110 LABEL(LineDown)
111  IF(NOT(y = 10))
112   y := y + 1
113   CALL(TypeFruit)
114  Else 
115   BEEP 
116  ENDIF
117  RETURN
118 LABEL(PageUp)
119  y := 1
120  CALL(TypeFruit)
121  RETURN
122 LABEL(PageDown)
123  y := 10 
124  CALL(TypeFruit)
125  RETURN
126 LABEL(TypeFruit)
127  vBlank := " " 
128  DIALOGADDTEXT(1000; 0; 60; vOldPos; 40; 10; 1; vBlank)
129  DIALOGADDTEXT(1000; 0; 60; y * 10; 40; 10; 1; List[y])
130  vOldPos := y * 10
131  RETURN
132 LABEL(MsgBox)
133  MESSAGEBOX(vStatus; "Message Box"; "Do you want to cancel this message?"; YesNo! |
    IconQuestion!)
134  IF(vStatus = MessageBox.Yes!)
135   WM_ACTIVATE := 0
136  ENDIF 
137  RETURN
Lines

Description

Lines 1-3 Comments about the macro.
Line 2 Macros are generally saved to the default macros directory.
Line 4 Corel WordPerfect identified as the default application.
Lines 5-7 Comments identify the opening CALL statements which outline and define the macro's basic operations.
Line 8 Call LABEL(InitializeVariables), which initializes all variables (lines 16-38). A run-time error occurs if you reference a variable that has not been assigned a value. See PerfectScript VarErrChk command.
Line 9 Call LABEL(CreateDlg) after LABEL(InitializeVariables) returns. LABEL(CreateDlg) creates a dialog box in memory (lines 39-47). It does not display the dialog box.
Line 10 Call LABEL(DisplayDlg) after LABEL(CreateDlg) returns. LABEL(DisplayDlg) displays the dialog box and identifies a callback function. See PerfectScript DialogShow command.
Line 11 CALL LABEL(MessageLoop) after LABEL(DisplayDlg) returns. LABEL(MessageLoop) starts a message loop that suspends the dialog box for callback function (lines 61-74).
Line 12 CALL LABEL(QuitMacro) after LABEL(MessageLoop) returns. LABEL(QuitMacro) removes the dialog box from memory and ends the macro.
Lines 13-15 Comments identify LABELs that correspond to the opening CALL statements (lines 8-12).
Lines 16-38 LABEL(InitializeVariables) initializes all variables.
Lines 17-25 Initialize variables with numbers that correspond to positions on the scroll bar. See PerfectScript DialogAddScrollBar command.
Line 26 The position of the most recent list item displayed in the dialog box. This position is cleared of text when a new list item is displayed (lines 127-128).
Line 27 The current position for displaying a new list item (line 129).
Lines 28-30 Initialize variables to contain Windows message numbers. Using variables makes the macro easier to read. The variable names are user defined, but match the Windows message names. See PerfectScript DialogShow command.
Line 31 Initialize the loop variable. In this example, vLoop does not receive a new value. The loop ends when the macro ends (line 57). It is possible to end the message loop and not the macro by changing the value of vLoop.
Line 32 Creates a 10-element array named List.
Lines 33-37 Fills array with the names of 10 fruits. Variable vElement identifies the element to fill.
Line 38 RETURN sends macro execution to CALL(CreateDlg).
Lines 39-47 LABEL(CreateDlg) creates a dialog box in memory.
Lines 42-44 A FORNEXT statement creates a list of names. The Control parameter of DIALOGADDTEXT is set to 0 to allow this command to execute in a FORNEXT statement. This is possible for controls that do not accept input.
Line 43 List is a 10-element array. The initial value of variable yPos is also 10. Dividing yPos by 10 reduces yPos to a number that corresponds to an element in the array. DIALOGADDTEXT uses the number to display the contents of the corresponding element.
Line 44 ENDFOR closes the FORNEXT statement (line 42).
Line 45 Displays the first list item in a second column.
Line 46 Displays the initial thumb position
Line 47 RETURN sends macro execution to CALL(DisplayDlg).
Lines 48-50 LABEL(DisplayDlg) displays the dialog box and identifies the callback function MsgLoop. RETURN sends macro execution to CALL(StartMessageLoop).
Lines 51-54 LABEL(StartMessageLoop) starts the message loop that suspends the dialog box for callback functions (lines 61-74). RETURN sends macro execution to CALL(QuitMacro).
Lines 55-57 LABEL(QuitMacro) removes the dialog box from memory and ends the macro.
Lines 58-60 Comments identify the callback function.
Lines 61-74 Callback function MsgLoop responds to three Windows messages and one Control parameter message. See PerfectScript DialogShow command.
Line 62 SWITCH tests the fifth element of the callback function array. See PerfectScript DialogShow command.
Lines 63-64 A WM_SYSCOMMAND message is received when the user chooses Close from the system menu box, double-clicks the system menu box, or presses Alt+F4. Macro execution jumps to LABEL(QuitMacro).
Lines 65-66 A WM_VSCROLL message is received when the user clicks the scroll bar. The macro calls LABEL(ScrollCtrl).
Lines 67-68 A WM_ACTIVATE message is received when the dialog box is activated. The macro calls LABEL(MsgBox).
Line 69 ENDSWITCH closes the SWITCH statement (line 62).
Lines 70-73 SWITCH tests the third element of the callback function array and determines when Cancel is chosen. See PerfectScript DialogShow command. An IF statement also works here. There is often more than one choice to test.
Line 74 RETURN sends macro execution to the message loop (lines 52-53).
Lines 75-96 LABEL(ScrollCtrl) tests the wParam of the MW_VSCROLL message (line 76).
Line 76 SWITCH tests the sixth element(wParam value passed with WM_VSCROLL) of the callback function array to determine the mouse's location when clicked.
Lines 77-94 See PerfectScript DialogAddScrollBar command for details about WM_VSCROLL messages.
Lines 77-78 Scroll bar's right arrow clicked. Call LABEL(LineUp).
Lines 79-80 Scroll bar's left arrow clicked. Call LABEL(LineDown).
Lines 81-82 Area between the right arrow and thumb clicked. Call LABEL(PageUp).
Lines 83-84 Area between the left arrow and thumb clicked. Call LABEL(PageDown).
Lines 85-86 Position of thumb after it is dragged, passed as the low-order word of lParam in the seventh element of the callback function array. Call LABEL(Thumb).
Lines 87-88 Current position of thumb as it is dragged, passed as the low-order word of lParam in the 7th element of the callback function array. Call LABEL(Thumb). Lines 87-88 call the same function as lines 85-86 and have comment marks (//). To test lines 87-88, add comment marks (//) to lines 85-86 and remove them from 87 and 88 (see PerfectScript // command).
Lines 89-90 Home key pressed while the scroll bar has the input focus. Call LABEL(PageUp).
Lines 91-92 End key pressed while the scroll bar has the input focus. Call LABEL(PageDown).
Lines 93-94 Scroll bar activity has ended. Display the current thumb position, contained in variable y.
Line 95 ENDSWITCH closes the SWITCH statement (line 76).
Line 96 RETURN sends macro execution to LABEL(MsgLoop) callback function.
Lines 97-101 LABEL(Thumb) retrieves the thumb position after it is dragged (MsgLoop[6] = SB_THUMBPOSITION), or as it is dragged (MsgLoop[6] = SB_THUMBTRACK).
Line 98 Assign the value of MsgLoop[7] (element 7 of the callback function array) to variable y.
Line 99 Calculate the low-order word of variable y using the bitwise AND operator. See Bitwise Operators in Chapter 4: Expressions. The value assigned to y is the current thumb position.
Line 100 Call LABEL(TypeFruit) to display the list item that corresponds to the current thumb position.
Line 101 RETURN sends macro execution to LABEL(ScrollCtrl).
Lines 102-109 LABEL(LineUp) is called when the right arrow is clicked to make the current line (value of y) equal to the current thumb position.
Lines 103-105 If the current line is not 1, assign the value of y - 1 to y, and call LABEL(TypeFruit) to display the list item that corresponds to the current thumb position.
Lines 106-107 Beep if the value of y equals 1 (if the first item is displayed). (Try changing this so the last item is displayed.)
Line 108 ENDIF closes the IF statement (line 103).
Line 109 RETURN sends macro execution to LABEL(ScrollCtrl).
Lines 110-117 LABEL(LineDown) is called when the left arrow is clicked to make the current line (value of y) equal to the current thumb position.
Lines 111-113 If the current line is not 10, assign the value of y + 1 to y, and call LABEL(TypeFruit) to display the list item that corresponds to the current thumb position.
Lines 114-115 Beep if the value of y equals 10 (if the last item is displayed). (Try changing this so the first item is displayed.)
Line 116 ENDIF closes the IF statement (line 111).
Line 117 RETURN sends macro execution to LABEL(ScrollCtrl).
Lines 118-121 LABEL(PageUp) is called when the area between the right arrow and thumb is clicked.
Line 119 Assign 1 to variable y to make 1 the current line and thumb position.
Line 120 Call LABEL(TypeFruit) to display the first list item on the first line.
Line 121 RETURN sends macro execution to LABEL(ScrollCtrl).
Lines 122-125 LABEL(PageDown) is called when the area between the left arrow and thumb is clicked.
Line 123 Assign 10 to variable y to make 10 the current line and thumb position.
Line 124 Call LABEL(TypeFruit) to display the last list item on the last line.
Line 125 RETURN sends macro execution to LABEL(ScrollCtrl).
Lines 126-131 LABEL(TypeFruit) displays a list item on the line that corresponds to the current thumb position.
Line 127 Assign blank spaces to variable vBlank to erase the previous list item when a new one is displayed.
Line 128 Erase the previous list item. The vertical position is contained in variable vOldPos that has an initial value of 10 (line 26). This value is updated (line 130) every time LABEL(TypeFruit) is called.
Line 129 Type a new list item at the current thumb position times 10 (the current line position). The current thumb position (value of y) identifies the current list item (List[y]).
Line 130 Assign the current line position to variable vOldPos to be used (line 128) when this subroutine is called again.
Line 131 RETURN sends macro execution to the subroutine's caller.
Lines 132-137 LABEL(MsgBox) is called when the dialog box is activated (lines 67-68). If you choose No, the dialog box is activated when the message box is dismissed and LABEL(MsgBox) is called again. The message box is called until the user chooses Yes (lines 134-136).
Line 133 See PerfectScript MessageBox command.
Lines 134-136 If variable vStatus equals MessageBox.Yes!, assign 0 to WM_ACTIVATE. Changing the value of WM_ACTIVATE invalidates it as a Windows activate message (lines 30 and 67-68).
Line 137 RETURN sends macro execution to LABEL(MsgLoop) callback function.

CALENDAR.WCM

DDE is a method of the Windows operating system that transfers commands and other information between applications. For example, you can use DDE to execute Novell GroupWise commands from Corel WordPerfect.

CALENDAR.WCM opens the Novell GroupWise 4.1 day calendar.

1 // Name: CALENDAR.WCM
2 // Directory: C:\OFFICE8\MACROS\...
3 // Description: Open Novell GroupWise Day calendar
4 // Method: Dynamic Data Exchange
5 APPLICATION(WP; "WordPerfect"; Default; "EN")
6 //*********************************************************
7 //MAIN CALL STATEMENTS
8 //*********************************************************
9 CALL(IsGroupWiseRunning)
10 CALL(OpenDayCalendar)
11 CALL(QuitMacro)
12 //*********************************************************
13 //MAIN LABEL STATEMENTS
14 //*********************************************************
15 LABEL(IsGroupWiseRunning)
16  IF(APPLOCATE("Novell GroupWise 4.1") = 0)
17   vPath := "c:\ofwin40\"
18   vResult := APPEXECUTEEXT(vPath + "ofwin.exe"; 0)
19   IF(vResult 32)
20    SWITCH(vResult)
21    CASEOF 2: CALL(FileNotFound)
22    CASEOF 3: CALL(PathNotFound)
23    DEFAULT: CALL(ErrorMsg)
24    ENDSWITCH
25   ENDIF
26  ENDIF
27  RETURN
28 LABEL(OpenDayCalendar)
29  hDay := APPLOCATE("Day")
30  IF(hDay)
31   APPACTIVATE(hDay)
32  Else
33   hConv := DDEINITIATE("GROUPWISE"; "COMMAND")
34   IF(hConv)
35    DDEEXECUTE(hConv; "ViewOpenNamed(ViewName:""Day""; ViewType:Calendar!)")
36   Else
37    CALL(QuitMacro)
38   ENDIF
39  ENDIF
40  RETURN
41 LABEL(QuitMacro)
42  DDETERMINATEALL
43  QUIT
44 //*********************************************************
45 //SECONDARY LABEL STATEMENTS
46 //*********************************************************
47 LABEL(FileNotFound)
48  BEEP
49  vMessage := "File not found - ending macro" 
50  GO(DisplayMessage)
51 LABEL(PathNotFound)
52  BEEP
53  vMessage := "Path not found - ending macro"
54  GO(DisplayMessage)
55 LABEL(ErrorMsg)
56  BEEP
57  vMessage := "Unable to launch GroupWise 4.1 - ending macro"
58  GO(DisplayMessage)
59 LABEL(DisplayMessage)
60  MESSAGEBOX(var; "ERROR"; vMessage; Ok! | IconExclamation!)
61  GO(QuitMacro)
Lines

Description

Lines 1-4 Comments about the macro.
Line 2 Macros are generally saved to the default macros directory.
Line 5 Corel WordPerfect identified as the default application.
Lines 6-8 Comments identify the opening CALL statements, which outline and define the macro's basic operations.
Line 9 Call LABEL(IsGroupWiseRunning) to determine if Novell GroupWise is running.
Line 10 Call LABEL(OpenDayCalendar) to initiate a DDE conversation with Novell GroupWise and send an Office command to open the Day calendar view.
Line 11 Call LABEL(QuitMacro) to end the macro.
Lines 12-14 Comments identify the main LABEL statements.
Lines 15-27 LABEL(IsGroupWiseRunning) determines if Novell GroupWise is running. If it is not running, this LABEL(IsGroupWiseRunning) starts it.
Line 16 APPLOCATE returns the Novell GroupWise window handle if the window title is found, or returns 0 if not. If 0 is returned, the next statement is executed (line 17). If a window handle is returned, RETURN (line 27) sends macro execution to CALL(OpenDayCalendar). Another way to write the statement is:

vResult := APPLOCATE("Novell GroupWise 4.1"

IF(vResult = 0)

Line 17 If necessary, change this line to the directory that contains the Novell GroupWise program files.
Line 18 APPEXECUTEEXT returns the application handle if Novell GroupWise is started (line 16), or returns an error value less than 32 if it is not started. See PerfectScript AppExecuteExt command.
Line 19 If vResult is less than 32 (error occurred), execute SWITCH statement (lines 20-24).
Lines 20-23 IF vResult equals 2, call LABEL(FileNotFound). If vResult equals 3, call LABEL(PathNotFound). For any value less than 32, call LABEL(ErrorMsg). See PerfectScript AppExecuteExt command for a list of error values.
Line 24 ENDSWITCH closes the SWITCH statement (line 20).
Line 25 ENDIF closes the IF statement (line 19).
Line 26 ENDIF closes the IF statement (line 16).
Line 27 RETURN sends macro execution to CALL(OpenDayCalendar).
Lines 28-40 LABEL(OpenDayCalendar) determines if the Day calendar view is already open.
Line 29 APPLOCATE returns the Calendar view window handle if the window title is found, or returns 0 if the window title is not found. The handle or 0 is assigned to variable hDay.
Lines 30-31 If variable hDay equals a window handle (a non-zero number), use APPACTIVATE to activate the Calendar view. The statement IF(hDay) is equivalent to IF(hDay 0).
Lines 32-33 IF variable hDay equals 0 (Else), initiate a conversation with Novell GroupWise and assign the result to variable hConv.
Lines 34-35 If variable hConv equals a window handle (a non-zero number), execute the ViewOpenedNamed Office command.
Lines 36-37 If variable hConv equals 0 (conversation not initiated), call LABEL(QuitMacro).
Line 38 ENDIF closes IF statement (line 34).
Line 39 ENDIF closes IF statement (line 30).
Line 40 RETURN sends macro execution to CALL(QuitMacro).
Lines 41-43 LABEL(QuitMacro) ends the macro.
Lines 44-46 Comments identify the SECONDARY label statements.
Lines 47-50 LABEL(FileNotFound) beeps, assigns a file not found message to variable vMessage, and sends macro execution to LABEL(DisplayMessage).
Lines 51-54 LABEL(PathNotFound) beeps, assigns a path not found message to variable vMessage, and sends macro execution to LABEL(DisplayMessage).
Lines 55-58 LABEL(ErrorMsg) beeps, assigns an unknown error message to variable vMessage, and sends macro execution to LABEL(DisplayMessage).
Lines 59-61 LABEL(DisplayMessage) displays the appropriate error message and sends macro execution to LABEL(QuitMacro).
Line 60 MESSAGEBOX displays the contents of variable vMessage (lines 49, 53, and 57).