Assignment operator (:=)

Value1 := Value2

Value1

A reference to a property which should be assigned the value on the right-hand side of :=.

Value2

The value to assign to the property.

Returns

The value assigned to the property.

Assigns a value to a property. Field1 := 4Field1 := 4 and Field1.Value := 4Field1,Value := 4 both assign the value 4 to the Value property of Field1.

This operator can only be used from an action formula. It is typically invoked from a formula associated with the OnPress property of a formula button.

Read-only properties (such as FormattedValue of number fields and Fields of form screens) cannot be assigned to. Properties with formulas associated with them cannot be assigned to either.

:= can also be used to assign a value to a name defined through the LET function.

This operator is specific to Calcapp.

Creating a button that performs calculations

Ordinarily, Calcapp performs calculations as the user types, with results appearing instantaneously. Sometimes, though, it is better if results appear only after a button is pressed.

:= can be used to realize such a button. Create a formula button and associate a formula such as the following with its OnPress property:

ResultField1 := InputField1 * 2; ResultField2 := ABS(InputField1)ResultField1 := InputField1 * 2;; ResultField2 := ABS(InputField1)

The key is to separate different calculations with ;;;. A single button can assign values to any number of fields.

Assigning a value to a property

:= can assign values to any property, not just the Value properties of number fields, text fields, date and time fields and other fields.

For instance, this action formula makes a text box invisible:

TextBox1.Visible := FALSETextBox1,Visible := FALSE

This action formula makes an enabled button disabled, and a disabled button enabled:

Button1.Enabled := NOT(Button1.Enabled)Button1,Enabled := NOT(Button1,Enabled)

Sending a report and giving feedback using :=

The following action formula sends a report through email and makes a text box visible if sending the report succeeds. Another text field — containing an error message — is made visible if sending the report fails:

AWAIT(EMAILREPORT({ App }, "test@example.com"), OnSuccess: SuccessBox.Visible := TRUE; ErrorField.Visible := FALSE, OnFailure: ErrorField.Value := Error.Message; ErrorField.Visible := TRUE; SuccessBox.Visible := FALSE)AWAIT(EMAILREPORT({ App }; "test@example.com"); OnSuccess: SuccessBox,Visible := TRUE;; ErrorField,Visible := FALSE; OnFailure: ErrorField,Value := Error,Message;; ErrorField,Visible := TRUE;; SuccessBox,Visible := FALSE)

The formula above names the last two parameters OnSuccess — invoked when sending the report succeeds — and OnFailure — invoked when sending the report fails — to aid readability. Naming parameters is optional.

If sending the report is successful, a text box named SuccessBox is made visible and a text field, named ErrorField and used to display an error message, is made invisible.

The OnFailure parameter has access to a value named Error, which among other things provides a text string named Message, explaining what went wrong. (Refer to the documentation for AWAIT and EMAILREPORT to learn more.)

If sending the report fails, ErrorField is made visible and the error message is assigned to the value of ErrorField.

Examples

Field1 := 4Field1 := 4

Assigns 4 to the Value property of Field1.

Field1.Value := 4Field1,Value := 4

Assigns 4 to the Value property of Field1. Spelling out the name of the Value property is optional.

ResultField1 := InputField1 * 2; ResultField2 := ABS(InputField2)ResultField1 := InputField1 * 2;; ResultField2 := ABS(InputField2)

Assigns InputField1 * 2InputField1 * 2 to the value of InputField1 and ABS(InputField2)ABS(InputField2) to the value of ResultField2. Use ;;; to separate statements.

TextBox1.Visible := TRUETextBox1,Visible := TRUE

Makes TextBox1 visible.

TextBox1.Visible := !TextBox1.VisibleTextBox1,Visible := !TextBox1,Visible

Toggles whether TextBox1 is visible.

AWAIT(EMAILREPORT({ App }, "test@example.com"), SuccessBox.Visible := TRUE)AWAIT(EMAILREPORT({ App }; "test@example.com"); SuccessBox,Visible := TRUE)

Emails a report and displays a text box named SuccessBox if sending the report is successful.