Operators

Operators allow you to manipulate text strings and perform calculations.

 

The Operators available are:

=

equals

+

add

-

subtract

*

multiply

\

integer division, i.e. 5/2 = 2

/

floating point or integer division depending upon the value of the Floating Point Division Property – see below)

&

string concatenation

%

modulo, returns the integer remainder after the division of two numbers, e.g. 5 % 2 = 1

 

Operator expressions can include actual values, variables, Scripting Methods and your own custom Functions. For example:

Num1 = 10 / 2

Profit = Price * Units - Cost

Num2 = Num1 + 3 + 6

Profit = Margins(Price, Cost) * Units

Name = Surname & ","

a = b + GetControlValue(Num1)

Name = Name & FirstName

a = GetControlValue(Num1) + GetControlValue(Num2)

 

Arithmetic operators are handled with the following precedence:

*, \ , /and % (left to right)

+ and - (left to right)

Brackets can be used to override this order of precedence if needed, e.g.:

Num1 = (10 + 2) * (Num2 + Num3)

staticCtrl1.Text = GetControlValue("NumUnits") + (((Num3 * Num4) - (Num5 * Num6)) * Num8)

Num1 = Num2 – (-5) + Num3 * MyFunc(Var1) / MyFunc(Num4) * ((Num4 * Num5) – Num6)

 

Division can be performed using the '\' or '/' operators:

  • The '\' operator always performs integer division, e.g. 5\2 will return 2.

  • The behaviour of the '/' operator, on the other hand, depends upon the value of the Floating Point Division Property. This Property can be found in the Miscellaneous category under the Project Properties. To display the Project Properties, select the root node in the Forms Pane under any Platform.

    If the Floating Point Division Property is set to True, the '/' operator will perform floating point division, i.e. 5/2 will return 2.5.

    If the Property is set to False, the '/' operator will perform integer division, e.g. 5/2 will return 2.

    By default, the Property is set to True.

    In the App Studio, if you load an app which was created using Digitise Apps' predecessor MX prior to v6.1, a message will be displayed reminding you that the app only used integer division and asking if you would like to use floating point division instead.

    If you choose the Yes button, the Floating Point Division Property will be set to True and you will need to check your Scripts for any division and if necessary edit them appropriately, e.g. to use the Integer Division operator, '\'.

    If you answer No, the Floating Point Division Property will be set to False which will cause your app to continue to work as it did before.

    • '=' is used to set the contents of variables to a specified value or to the return value from a Function.

    • You cannot use the string concatenation operator, '&', in the same expression as the arithmetic operators.

    • At runtime, if a variable containing Null is used with the string concatenation operator '&', the variable will be treated as containing an empty string.

    • You can include both your own custom functions and the built-in Methods within an expression.

    • Do not use the '+' sign to indicate positive numbers, e.g. +5 is not allowed.