Skip to content

IfThen ​

The IfThen function checks the expression passed as AValue, and returns the value of ATrue if the expression is True, or returns the value of AFalse if the expression is False.

  • AValue is the expression that will be determined to be either True or False.
  • ATrue is the string to return if the expression evaluates as True.
  • AFalse is the string to return if the expression evaluates as False.

INFO

AValue can check anything - but the function is case-sensitive and the match must be exact to return True.

Declaration: Function IfThen( AValue : Boolean; const ATrue : string; AFalse : string) : string;

A simple example as below.

pascal
procedure ScriptEvent (var Value : variant);
var
  aStr, aName : string;
  aCount : integer;
begin
  aCount := 1;                              //As a numeric function
  aStr := ifthen(aCount=1,'aCount is 1', 'aCount is not 1');
  LogInfo(aStr);                            //True
  aCount := 57;
  aStr := ifthen(aCount=1,'aCount is 1', 'aCount is not 1');
  LogInfo(aStr);                            //False

  aName := 'Susan';                        //As a string function
  aStr := ifthen(aName='Susan','Susan is in the house!', 'Susan has gotten lost!');
  LogInfo(aStr);                           //True
  aName := 'Fred';
  aStr := ifthen(aName='Susan','Susan is in the house!', 'Susan has gotten lost!');
  LogInfo(aStr);                           //False
  aName := 'SUSAN';
  aStr := ifthen(aName='Susan','Susan is in the house!', 'Susan has gotten lost!');
  LogInfo(aStr);                           //False
  LogInfo('');

 end;