UniVerse Tips And Tricks

From Pickwiki
Jump to navigationJump to search

Various tips and tricks for UniVerse.

<toc>

# Inline conditionals

The resulting value of a conditional can be used in a statement as long as it is wrapped in parentheses. This simplifies logic that only returns one of two possible values. It is also handy for setting the value of boolean variables.

PRINT (IF FLAG THEN "YES" ELSE "NO")
EMPTYSW = ("" EQ CONVERT(@FM:@VM:@SM:" ", "", ITEM))

# READV "0"

When you only need to see if a record id exists on file, you can READV attribute "0" (zero). This way, Universe does not have to read in any part of the record (making it theoretically faster.) Note that you check the ELSE clause, since the record id could be "0" or "", making a boolean check return an unintentional "false".

 READV SCRAP FROM FILE, RECORDID, 0 ELSE
    * the id does not exist on file
    * cannot use SCRAP as a flag if the id is "0" or null
 END

# Multi-valued ICONV/OCONV

Multiple ICONV/OCONV operations can be performed at the same time by separating the codes with value-marks (@VM).

 * extract letters and convert them to uppercase
 LETTERS = OCONV(RESPONSE, "MCA":@VM:"MCU")

# Passing variables by value, not reference

By default, variables are passed into subroutines and functions by reference where they can potentially change. To prevent a subroutine from changing a variable's value, you can pass it by value by simply enclosing it in parentheses.

 * CM.ID and ORDER.TOTAL are passed by value so they won't change.
 TAX = GET.TAX.AMOUNT((CM.ID), (ORDER.TOTAL))

# Forcing string comparison on numbers

Sometimes you want to compare strings, but they may be numeric, e.g. the strings "0" and "0.00" are NOT equal. To force string comparison, temporarily concatenate a non-numeric string when comparing.

X = "0"
Y = "0.00"
EQUALS.SW = (X EQ Y)   ;* numerically they are equal, evaluates "true"
STRING.EQUALS.SW = ("!":X EQ "!":Y)  ;* string comparison correctly evaluates "false"

Tags: inline condition conditional readv iconv oconv tip tips trick tricks

http://www.autopower.com/rgozar/pixel.gif