Custom Token Example 1: Mathematical Calculation

In the first example, you will create a Custom Token with a simple formula, and then insert it into a Text Box.

 

1. Click on NewAdd (Add) in a docked Custom Token window.

2. Edit New Custom Token to read Mathematical Calculation.

3. In the Formula area below the splitter, enter the following: =100 * 30.

4. Click on Mathematical Calculation to highlight/select it. Your Custom Token window should look like Figure 12.53.

 

 

Figure 12.53  Custom Token Example 1

Figure 12.53  Custom Token Example 1

 

 

 

5. Create a Text Box on a layout page.

6. In the Text Box, enter the phrase: The number of stars in the sky is: <space>

7. Right-click at the end of the text, and select Insert Token from the pop-up menu.

8. At the bottom of the Insert a Token dialog (Figure 12.54), make sure that the Custom category is open (click on the triangle next to Custom, if necessary), and select Mathematical Calculation.

 

 

Figure 12.54  Insert a Token Dialog

Figure 12.54  Insert a Token Dialog

 

9. With Mathematical Calculation highlighted, Click the Insert button. The Text Box should now read: "The number of stars in the sky is: 3000.00". (The default numeric output for a numeric result is two decimal places. This can be changed by right-clicking on the token in the text box, selecting Format Token from the pop-up menu, and changing the value on the Output Format page with the spin control). Once the Text Box is no longer in edit mode, the Mathematical Calculation token will display its result without a gray background.

 

This example demonstrates that when a Custom Token is inserted into a Text Box, its formula is calculated and the result is displayed.