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.

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