Util.Compare

Top  Previous  Next

 

Syntax

function Util.CmpVals(Value1, Value2: variant): integer

 

Alternative Names

ibec_CmpVals

 

Description

Compares Value1 and Value2 and returns an integer value as a result.

 

Returns 0 on equal values, 1 if Value1 is greater than Value2 and -1 if Value1 is less than Value2. If the values cannot be compared, NULL is returned.

 

Value1 and Value2 don't have to be the same type, but should be able to be converted.

 

See Also

Util.IIF

 

Example

execute UDSBlock

as

declare variable i integer;

begin

  i = 0;

  while (i < 5)

  do begin

  GUI.ShowMessage(Util.IIF(Math.Mod(i, 2) = 0, i || ' is even.', i || ' is odd.'));

  i = i + 1;

     end;

 

  CmpResult = Util.Compare(1, 4);

  if (CmpResult = 1)

  then GUI.ShowMessage('1 is larger than 4');

  else if (CmpResult = -1)

  then GUI.ShowMessage('1 is less than 4');

  else GUI.ShowMessage('1 and 4 are equal');

  

  /* '1' will be converted to 1, result -1 */

  CmpResult = Util.Compare('1', 4);

  

  /* cannot be compared, will result in NULL */

  CmpResult = Util.Compare('This is text', 1000);

end