Advanced - Using Integer Variables

 

The object of the completed macro is to generate three random numbers from 1 to 100 and display the results. This macro requires using Integer Variables as well as Arrays.

 

 

Setting up the Macro

 

1.From the Macro Express Pro - Explorer menu click on Macro > New Macro to open the Create New Macro window.

2.Hot Key should already be selected as the Activation.

3.Click on the HotKey edit box to place the cursor in this field.

4.Hold down the CTRL key, the SHIFT key and the R key all at the same time and release them.

5.CTRL+SHIFT+R should appear in the edit box. This is the hot key we will define for the macro.

6.Enter "Generate Random Numbers" (without the quotes) in the Nickname field.

7.Click OK to open the Script Editor.

8.In the Script Editor click on the Scope tab and make sure that the macro scope is set to global.

9.Click on the Script tab to start building the macro.

 

 

Building the Macro in the Script Editor
 

1.  Scroll through the list of commands and expand the Variables category. Double click on the Variable Set Integer command to open the window of the same name.

2.  From the drop down list select the Set to a Random Value option.

 

Creating the variable and array
 

a.  Place the cursor in the Destination Variable field to display the Variables button to the right of the field.

b.  Click on the Variables button to open the Insert Variable window.

c.  Click on the Add button to open the Variable Properties window.

d.  Enter "Random" in the Variable Name field.

e.  From the drop down Variable Type list select Integer Variables.

f.  Check the box next to Create as an Array.

g.  Enter 3 (three) in the Elements field and click OK to return to the Insert Variable window.

h.  Expand the list of Integer variables (click on +) to see the Random variable created.

i.  Highlight the Random variable to see Random[ ] displayed in the Variable Name field.

j.  Insert the number 1 (one) between the brackets so it displays as Random[1].

k.  Click OK to return to the Variable Set Integer command.

 

3.  The Destination Variable field should now display %Random[1]% as the variable.

4.  Enter the number 1 (one) in the Minimum Value field.

5.  Enter the number 100 (one hundred) in the Maximum Value field.

6.  Click OK to save the command and place it in the Script Editor.

 

 

Generating the Random Numbers
 

7.  In the Script Editor highlight the Variable Set Integer command shown in the script and click on the Duplicate button  twice (on the right hand side of the script) so that you should now see three identical lines in the script.

8.  Double click on the second line in the script to open the Variable Set Integer command.

9.  Edit the Variable name by replacing the 1 (one) in brackets with a 2 (two). It should now display as %Random[2]%.

10.  Click OK to save and return to the Script Editor.

11.  Double click on the third line in the script to open the Variable Set Integer command.

12.  Edit the Variable name by replacing the 1 (one) in brackets with a 3 (three). It should now display as %Random[3]%.

13.  Click OK to save and return to the Script Editor.

 

 

Have the macro display the results

These next steps set up the display of the three random numbers in a text box. After completing lines 14 through 27, the Text Box Display command window should look like the image below.

 

14.  Scroll through the list of commands and expand the Dialogs category. Double click on the Text Box Display command to open the window of the same name.

15.  Insert "Display random numbers" in the Header field.

16.  Place the cursor in the Text Box field and the Variables button will appear to the right of the field.

17.  Click on the Variables button and expand the Integer Variables type.

18.  Select the Random variable to place Random[ ] in the Variable Name field.

19.  Insert 1 (one) between the brackets so that it reads as Random[1] and click OK.

20. This places %Random[1]% in the Text Box field.

21.  Copy the text %Random[1]% to the clipboard. Highlight the text and press Ctrl + C to copy to the clipboard.

22.  Move the cursor to the second line (Right Arrow and the Enter key).

23.  Press Ctrl + V to paste the text into the second line.

24.  Move the cursor to the third line and press Ctrl + V to paste again.

25.  You should now have three identical lines of %Random[1]%.

26.  In the second line, replace the 1 (one) with 2 (two) so that it reads %Random[2]%.

27.  In the third line, replace the 1 (one) with 3 (three) so that it reads %Random[3]%.

28.  Click on the OK button to save and return to the Script Editor.


 

 

 
 

In the Script Editor, click on Script > Save Macro to save the macro just created.

 

 

Macro Script

The macro script should look like what is displayed below. If the macro does not look like this, arrange the commands so that they are in the following order.


 

Variable Set Integer %Random[1]% to a random value between 1 and 100

Variable Set Integer %Random[2]% to a random value between 1 and 100

Variable Set Integer %Random[3]% to a random value between 1 and 100

Text Box Display: Three Random Numbers

 

 

Testing the Macro

Press Ctrl + Shift + R to run the macro. A text box opens and displays three random numbers between 1 and 100.

 

 

üNote: If assigning original names to variables, rather than using T[1], D[1], etc., then the following characters are not allowed in the variable name:  [ ] < > , . - + = \ | / * %