Skip to main content

5-4-10 Global variables

A global variable is a variable that you can define and use as a valid text-type data parameter value between the VrInit and VrQuit functions.

When you define a global variable, you will be able to share the data output from higher-level applications across multiple forms.

For example, if the value for the company name or company address on a form is directly defined as static text during the form design, all forms on which the company name is printed as static text have to be changed individually if the company name changes.

However, if instead of static text, a field is set which uses a global variable showing the company name, all output data can be changed just by changing the value of the global variable in the upper level application, and you will not need to modify all of the XML form files.

Define a global variable and its initial value

In order to use a global variable in a calculation-formula and edit-formula, first define the global variable. You can set any variable as a global variable. Perform the following procedure to register the initial value of a global variable in the XML form file.

This section describes an example of registering a global variable from the Edit-formula dialog.

  1. Click the Set global variable button in the Edit-formula dialog.

    swd92user_p323.png

    "Edit-formula" dialog

  2. When the Global variable dialog appears, click the Add button.

    swd92user_p324.png

    "Global variable" dialog

  3. Set each item in the Add variable dialog.

    In the following example, the variable name is set as "$COMPANY$", the data is set as "ABC Corp." and "No initial value" is selected.

    After you have finished configuring the settings, click the OK button.

    swd92user_p325.png

    Specify the variable name and data

    Variable name

    Type the variable name.

    Even if you enter the variable name without enclosing it in "$" (for example, "COMPANY"), "$" will automatically be added before and after the variable name and will be registered as "$COMPANY$".

    Data

    Set any data as the initial value of the variable.

    The data is internally treated as text data. When entering the data, there is no need to enclose it with "" (double quotations), even when specifying text data.

    Only enclose it with double quotations if you want to enter the data as a string that will appear enclosed in double quotations, such as "ABC Corp." (displayed including the double-quotes).

    In this example, type in ABC Corp. (without double quotations).

    No initial value

    Used to determine the initial value when printing with the program.

    Add a check in the following cases:

    • When you want to dynamically change the value in the program.

    • When you are outputting with multiple XML form files that have different values registered to the same global variable name, and you want the second and subsequent XML form files to inherit the global variable value registered in the first XML form file.

  4. Confirm that the variable has been added to the list and click the OK button.

    swd92user_p326.png

    "Global variable" dialog

    Reference

    • If you want to modify a global variable that you have already set, click the Edit button.

      However, you cannot change the variable name during editing.

    swd92user_p327.png

    "Edit variable" dialog

    • When you want to delete a set global variable, click the Delete button.

Set a global variable in the field

This section describes how to set a defined global variable in the calculation-formula and edit-formula of a field.

In the following example, the global variable "$COMPANY$" is set in the edit-formula.

  1. Click the Reference global variable button in the Edit-formula dialog.

    swd92user_p328.png

    "Edit-formula" dialog

    Reference

    An undefined global variable name can be entered directly in the formula-text field. However, in such cases, you will not be able to register the initial value of the global variable. If you want to register the initial value, return to the previous section "Define a global variable and its initial value" to operate.

  2. The global variable names defined in the XML form file are displayed in a list.

    Select the global variable name to use, and then click the Add to formula-text button or double-click the global variable name.

    The selected global variable is entered.

    swd92user_p329.png

    The global variables you defined appear

    Reference

    In a global variable, the value is treated as text-type data.

    In order to treat it as numeric data, you must use the VAL function or the NUMVAL function to convert the data.

    For examples of settings, see "Specify an undefined global variable name ($<global_variable_name>$)".

Check the output result of a global variable

This section describes the method for checking how the global variable that you specified in the edit-formula will be output.

In the following example, ""Dear " + $COMPANY$" is set in the edit-formula.

  1. Enter ""Dear " + $COMPANY$" in the edit-formula.

    It is safer to input the global variable "$COMPANY$" from Reference global variable.

  2. Click the Check results button.

    swd92user_p330.png

    "Edit-formula" dialog

  3. Click the Confirm button.

    "ABC Corp." is obtained from the global variable, and the data "Dear ABC Corp." will appear with "Dear" added.

    swd92user_p331.png

    The confirmation result is displayed

    The Data field displays the Data value set in the Global variable dialog.

    Reference

    If you have defined the Data value, its value will appear as the initial value regardless of the setting that determines whether the global variable has an initial value or not.

    The setting that determines whether the global variable has an initial value will only be applied when the variable is actually executed from the program.

    Reference

    The result displays the data that was set when defining the global variable, as a string enclosed in double quotations ("").

    For example, if a string such as "Shibuya-ku, Tokyo" which is already enclosed in double quotation marks is set as the data of the global variable $ADDRESS$, ""Shibuya-ku, Tokyo"" will be displayed as the string, with double quotation marks added.

    This means that if "Shibuya x-x-x, "+$ADDRESS$ is set in the edit-formula, it is displayed as "Shibuya x-x-x, "Shibuya-ku, Tokyo"" in the Result field. If you want the data to appear as "Shibuya x-x-x, Shibuya-ku, Tokyo", make sure you do not enclose the "Shibuya-ku, Tokyo" string in double quotations when you enter the data value of the global variable.

    swd92user_p332.png

Specify an undefined global variable name ($<global_variable_name>$)

You may directly enter an undefined global variable name in the formula-text field.

However, you will not be able to register the initial value of the global variable.

In addition, global variable names entered directly in the formula-text field do not appear in the list of global variables.

Format

$<global_variable_name>$

Settings

In the calculation-formula or edit-formula of the field, define the variable name by enclosing it with "$".

When you want to set the initial value data of a global variable and save that data value in the XML form file, you must define the variable from the Set global variable button.

Usage examples

If you want to print multiple XML form files (FORM1 to FORM3) as delivery slips in a single spool, the following two patterns are available for designing the XML form file:

  • Pattern 1: When a global variable is not used

    Set the fixed values such as the company name and company address in the slip as static text. The data in Price, Unit Price, and Selling Price are each assumed to be the product of the currency rate multiplied by the value entered in each field. Obtain the value of the currency rate by creating a dummy field.

    swd92user_i119.png

FORM1

Item name

Field name

Data type

Calculation-formula

Edit-formula

Price

PRICE

Numeric value

PRICE*RATE

RATE (mask setting)

Numeric value

FORM2

Item name

Field name

Data type

Calculation-formula

Edit-formula

Unit Price

UNIT_PRICE

Numeric value

UNIT_PRICE*RATE

RATE (mask setting)

Numeric value

FORM3

Item name

Field name

Data type

Calculation-formula

Edit-formula

Selling Price

SELLING_PRICE

Numeric value

SELLING_PRICE*RATE

RATE (mask setting)

Numeric value

  • Pattern 2: When a global variable is used

    Set fixed values on the slip such as the company name and company address as fields instead of static text. Use the calculation-formula and edit-formula to specify the global variable in those fields. In addition, specify the currency rate as a global variable.

    swd92user_i120.png

FORM1

Item name

Field name

Data type

Calculation-formula

Edit-formula

Company

C_NAME

Text

$COMPANY$

Address

C_ADD

Text

$ADDRESS$

Price

PRICE

Numeric value

PRICE*VAL($RATE$)

FORM2

Item name

Field name

Data type

Calculation-formula

Edit-formula

Company

C_NAME

Text

$COMPANY$

Address

C_ADD

Text

$ADDRESS$

Unit Price

UNIT_PRICE

Numeric value

UNIT_PRICE*VAL($RATE$)

FORM3

Item name

Field name

Data type

Calculation-formula

Edit-formula

Company

C_NAME

Text

$COMPANY$

Address

C_ADD

Text

$ADDRESS$

Selling Price

SELLING_PRICE

Numeric value

SELLING_PRICE*VAL($RATE$)

Values set for the properties for each item

Reference

In a global variable, the value is treated as text-type data.

In order to treat it as numeric data, you must use the VAL function or the NUMVAL function to convert the data (see Pattern 2 in the above figure).

Differences in the program when you are using the global variable are as follows.

The printing result remains the same in either case.

Pattern 1: When a global variable is not used

VrInit()


VrSetForm("FORM1",1)
VrsOut("PRICE","1000")
VrsOut("RATE","1.2")
・・・
VrEndPage()

VrSetForm("FORM2",1)
VrsOut("UNIT_PRICE","500")
VrsOut("RATE","1.2")
・・・
VrEndPage()

VrSetForm("FORM3",1)
VrsOut("SELLING_PRICE","5000")
VrsOut("RATE","1.2")
・・・
VrEndPage()
VrQuit()

Pattern 2: When a global variable is used

VrInit()
VrsOut("$RATE$","1.2")
VrsOut("$COMPANY$","ABC Corp.")
VrsOut("$ADDRESS$","Shibuya x-x-x, Shibuya-ku, Tokyo")
VrSetForm("FORM1",1)
VrsOut("PRICE","1000")
・・・

VrEndPage()

VrSetForm("FORM2",1)
VrsOut("UNIT_PRICE","500")

・・・
VrEndPage()

VrSetForm("FORM3",1)
VrsOut("SELLING_PRICE","5000")

・・・
VrEndPage()
VrQuit()

Reference

If the company name or address is changed, you must modify the Blue part.

When the conversion rate is changed, you must modify the Red part.

As you can see from this example, you can use a global variable to reduce the amount of man-hours at the time of the form migration process.

Output result

The output result remains the same in either case.

First page

swd92user_i121.png

Second page

swd92user_i122.png

Third page

swd92user_i123.png