Tips   >   Functions   >   Other Functions

Other Functions

There are some many functions in Omnis Studio, we tend to forget about some of them.

I had created a "$retRemoveLeadingTrailingSpaces" method that used the mid() function in two While loops. I was proud of this fine function until Rudolf Bargholz pointed out the "trim()". Wow ... trim() did the job a lot easier in a single line of code and has all kinds of flexibility.

This topic covers some of the handy Omnis Studio functions not covered by the other topics in this section.

isclear - Is Clear

isclear(expression|fieldname)

Returns true if the expression or field has value NULL, zero (for numeric data types only) or empty.

Testing a value that can be null is always tricky. If you set a variable to a null value, then some comparison tests using the normal operators (= < >) will fail because null is not a value. For example:

Calculate NumVar as #NULL
If NumVar<>5
   Breakpoint {You will miss this breakpoint because null is not a value.}
Else
   Breakpoint {You will end up at this breakpoint because null is not a value.}
End If
Quit method

The isclear() function is handy where you want to test whether a value is null, empty, or zero (test for zero is only done for numeric variables. Trying to test for null, empty, or zero in a single line is very difficult to do (you have to use a pick function).

GOTCHA: Do not use the isclear() function inline with an OR test. The following If/Else will go to the Else

Calculate NumVar as #NULL
If isclear(NumVar)|NumVar>5
  ; assume it is null, zero, or greater than 5
Else
 ; assume it is non-null and less than or equal to 5
End if

...because it will evaluate to:

If TRUE | NULL

...which is NULL

So you go to the else part... because you have ended up with something that was not TRUE.

isnull - Is Null

isnull(expression|fieldname)

Returns true if the expression or field has value of NULL.

Testing a value that can be null is always tricky. If you set a variable to a null value, then some comparison tests using the normal operators (= < >) will fail because null is not a value. For example:

Calculate NumVar as #NULL
If NumVar<>5
   Breakpoint {You will miss this breakpoint because null is not a value.}
Else
   Breakpoint {You will end up at this breakpoint because null is not a value.}
End If
Quit method

GOTCHA: Do not use the isnull() function inline with an OR test. The following If/Else will go to the Else

Calculate NumVar as #NULL
If isnull(NumVar)|NumVar>5
  ; assume it is null or greater than 5
Else
 ; assume it is non-null and less than or equal to 5
End if

...because it will evaluate to:

If TRUE | NULL

...which is NULL

So you go to the else part... because you have ended up with something that was not TRUE.

mod - Modulus

mod(number1,number2)

Returns the remainder of a number division, that is, when number1 is divided by number2 to produce a remainder; it is a true modulus function.

Calculate Remainder as mod(6,4) ;; Returns 2

Calculate Remainder as mod(4,6) ;; Returns 4

Calculate Remainder as mod(-5,-2) ;; Returns -1

Calculate Remainder as mod(4,2) ;; Returns 0

msgcancelled - Message Cancelled

Use this function to detect if the user cancels in a Yes/No or No/Yes message which has the optional Cancel button checked.

Yes/No message (Cancel button) {Do you want to proceed?}
If flag false
If msgcancelled()
user chose Cancel
Else
user chose No
End If
Else
user chose Yes
End If

pick - Pick

pick(number,value0,value1[,value2]...)

Selects an item from a list of values (strings or numbers) depending on the value or result of the number argument. The number argument is rounded to an integer and used to select the item. value0 is returned if the result is 0, value1 if the result is 1, value2 if the result is 2, and so on.

If the number is less than zero or greater than the number of values in the list, an empty value is returned. Note the list of values can be a mixture of string and numeric values.

I find pick() to work great for working with radio button results, picking day or month short forms, and for concatenating fields where some of the field values might be empty.

rnd - Round

rnd(Value,DecimalPlaces)

Calculate RoundedValue as rnd(2.105693,5) ;; ReturnsĘ2.10569
Calculate RoundedValue as rnd(2.105693,3) ;; ReturnsĘ2.106
Calculate RoundedValue as rnd(0.5,1) ;; ReturnsĘ1

Warning

The return value of the rnd() function is a character string. This is the only representation of the returned number guaranteed to hold the result correctly, due to potential floating point inaccuracies. You need to be careful when comparing the return values of two calls to rnd(), since the return values are character strings, and will be compared as strings.

The rnd() function in Omnis does not round to the left of the decimal place. Excel does this with negative parameter values: -1,-2,-3. You can round to the left of the decimal place by:

  1. Multiplying the value by .1, .01, .001
  2. Rounding the multiplied value to zero decimal places.
  3. Multiplying the result by 10,100,1000,

The above can be compressed into one-liners as follows:

; Round to the left of the decimal. Nearest 10.
Calculate RoundedValue as rnd(1386*.1,0)*10 ;; ReturnsĘ1390

; Round to the left of the decimal. Nearest 100.
Calculate RoundedValue as rnd(1386*.01,0)*100 ;; ReturnsĘ1400

; Round to the left of the decimal. Nearest 1000.
Calculate RoundedValue as rnd(1386*.001,0)*1000 ;; ReturnsĘ1000