• No results found

Using the calculator control

In document pfcug (Page 179-184)

You use u_calculator (the PFC calculator control) to provide any of the following:

Using custom visual user objects

• Drop-down calculator for numeric or decimal values in an EditMask:

• Standalone calculator for use with an EditMask:

Users make calculations using the drop-down calculator. To enter numbers they either click the calculator’s buttons or use the numeric keypad with NumLock turned on. The calculator automatically enters calculation results into the associated field.

The PFC calculator control includes functions that allow you to control certain aspects of calculator behavior. For example, you call the of_SetCloseOnClick function to control whether the drop-down calculator closes when the user clicks the equal sign.

Using a drop-down calculator with a DataWindow control

The PFC calculator control works with DataWindow columns that have a numeric or decimal data type and are registered with u_calculator.

Depending on the registration option, the calculator displays when a registered column gets focus, when the user clicks the drop-down arrow, or when your code calls the pfc_DDCalculator event.

Controlling the visual cue To control the visual cue that displays in a DataWindow column for which the drop-down calculator is enabled, you supply an argument to the of_Register function:

Argument Result

NONE If the column uses the:

• DropDownListBox edit style, the calculator displays automatically when the column gets the focus • Edit or EditMask edit style, the calculator displays

Column edit styles When the service converts columns to the DropDownListBox edit style, properties that do not apply to

DropDownListBoxes are lost. Because of this, you typically use the drop-down calculator with columns that already use the DropDownListBox edit style, calling of_Register passing NONE.

v To use a drop-down calculator with DataWindow columns:

1 Find out which numeric or decimal DataWindow columns are appropriate for use with a drop-down calculator. For example, a salary column might use a calculator for use when determining raises. These columns must use the DropDownListBox, Edit, or EditMask edit style.

2 Place a u_dw-based DataWindow control on the window or user object. 3 Enable the drop-down calculator by calling the u_dw

of_SetDropdownCalculator function (this example is from a DataWindow Constructor event):

this.of_SetDropDownCalculator(TRUE)

4 Register columns one by one or all at once by calling the of_Register function. Of_Register includes an optional argument specifying the drop-down style:

this.iuo_calculator.of_Register("salary", & this.iuo_calculator.NONE)

5 Call additional functions as necessary to customize calculator behavior:

this.iuo_calculator.of_SetCloseOnClick(FALSE) this.iuo_calculator.of_SetInitialValue(TRUE)

Displaying the calculator programmatically

You can also display the drop-down calculator programmatically. This works with all of_Register options and is required for Edit and EditMask columns when using the NONE option.

DDLB Of_Register converts all registered columns to the DropDownListBox edit style. The calculator displays when the user clicks the down arrow, which disappears when the calculator displays

DDLB_WITHARROW Of_Register converts all registered columns to the DropDownListBox edit style. The calculator displays when the user clicks the down arrow, which remains when the calculator displays

Using custom visual user objects

v To display the drop-down calculator programmatically:

1 Place a u_dw-based DataWindow control on the window or user object. 2 Enable the drop-down calculator by calling the u_dw

of_SetDropdownCalculator function (this example is from a DataWindow Constructor event):

this.of_SetDropDownCalculator(TRUE)

3 Register columns to be displayed programmatically by calling the of_Register function. Of_Register includes an argument specifying the drop-down style. Programmatic display works best with the NONE style but can be used with any drop-down style:

this.iuo_calculator.of_Register("salary", & this.iuo_calculator.NONE)

4 Define a user event or visual control (such as a command button) that sets focus in the DataWindow control and calls the u_dw pfc_DDCalculator event: IF dw_1.SetColumn("salary") = 1 THEN dw_1.Event pfc_DDCalculator( ) END IF Using a drop-down calculator with an EditMask control

You can use a drop-down calculator with EditMask controls that use the numeric or decimal option type.

v To use a drop-down calculator with an EditMask control:

1 Place a u_em-based EditMask control on the window or user object. 2 Enable the drop-down calculator by calling the u_em

of_SetDropdownCalculator function (this example is from an EditMask Constructor event):

this.of_SetDropDownCalculator(TRUE)

3 Call additional functions as necessary to customize calculator behavior:

this.iuo_calculator.of_SetCloseOnClick(FALSE) this.iuo_calculator.of_SetInitialValue(TRUE)

4 Define a user event or visual control (such as a picture button) that displays the drop-down calculator by calling the u_em pfc_DDCalculator event:

Using a standalone

calculator You can create a standalone calculator by placing u_calculator directly on a window or user object.

v To create a standalone calculator:

1 Place a u_em-based EditMask control on the window or user object. 2 Place an instance of u_calculator on the window or user object. 3 Associate the drop-down calculator with the EditMask by calling the

u_calculator of_SetRequestor function (this example is from a u_calculator instance’s Constructor event):

this.of_SetRequestor(parent.em_1)

Setting calculator

options The PFC calculator control provides options that you can set to control calculator behavior: Close on click Controls whether the drop-down calculator closes when

the user clicks the equal sign:

this.of_SetDropDownCalculator(TRUE) ...

this.iuo_calculator.of_SetCloseOnClick(TRUE)

Initial value Controls whether the calculator initializes blank fields with a zero when it first displays:

this.of_SetDropDownCalculator(TRUE) ...

this.iuo_calculator.of_SetInitialValue(TRUE)

Use the Constructor event

You typically call the functions that control these behaviors in the u_dw or u_em Constructor event.

The examples in this discussion are from the Constructor event of a u_dw- based DataWindow control.

Using custom visual user objects

In document pfcug (Page 179-184)