Calculation Functions

Purpose The following functions are used in Superx++ within the <expr> clause of the <eval> statement to perform various calculation functions. These functions are not methods because they do not belong to any class or object.

The Calculation Functions
abs
returns the absolute value of a number
<eval>
   <expr>abs({number})</expr>
</eval>

where:
{number} is the number whose absolute value is to be returned

<node name="MyStudent">
   <Name>Johnnie B. Goode</Name>
   <Number>-7</Number>
</node>
<xout>abs = </xout>
<xout>
   <eval>
      <parm type="int" name="a_Num">
         <eval object="MyStudent/Number" />
      </parm>
      <expr>abs(a_Num)</expr>
   </eval>
</xout>

This code sends the following text to the output stream:
abs = 7

asc
returns the ASCII code of the first character of a string
<eval>
   <expr>asc({string})</expr>
</eval>

where:
{string} is the string whose first character will be used to find the ASCII code value

<node name="MyStudent">
   <Name>Johnnie B. Goode</Name>
   <Number>-7</Number>
</node>
<xout>asc = </xout>
<xout>
   <eval>
      <parm type="string" name="a_Val">
         <eval object="MyStudent/Name" />
      </parm>
      <expr>asc(a_Val)</expr>
   </eval>
</xout>

This code sends the following text to the output stream:
asc = 74

base
converts a number from one base to another and returns the converted number in base specified format
<eval>
   <expr>base({number}, {source base}, {dest base})</expr>
</eval>

where:
{number} is a string argument representing the whole number whose base is to be converted
{source base} is the base of the number to be converted as rendered in the {number} string
{dest base} is the base to which the number will be converted

The resulting number will be rendered in base specified format.
It is possible to write {number} as a base specified number. In this case you can omit the {source base} parameter. The format of the function would then become:
<eval>
   <expr>base({base specified number},, {dest base})</expr>
</eval>

Make sure to include the commas around the place for the {source base} parameter even though it is omitted.

<node name="MyStudent">
   <Name>Johnnie B. Goode</Name>
   <Number>255</Number>
</node>
<xout>base = </xout>
<xout>
   <eval>
      <parm type="string" name="a_Val">
         <eval object="MyStudent/Number" />
      </parm>
      <expr>base(a_Val, 10, 16)</expr>
   </eval>
</xout>
<xout>\r\nbase (again) = </xout>
<xout>
   <eval>
      <parm type="string" name="a_Val">b2_11111111</parm>
      <expr>base(a_Val,, 16)</expr>
   </eval>
</xout>

This code sends the following text to the output stream:
base = b16_FF
base (again) = b16_FF

ceil
returns the nearest whole number larger than the numerical argument
<eval>
   <expr>ceil({number})</expr>
</eval>

where:
{number} is the real number whose ceiling is to be found

<node name="MyStudent">
   <Name>Johnnie B. Goode</Name>
   <Number>8.5</Number>
</node>
<xout>ceil = </xout>
<xout>
   <eval>
      <parm type="string" name="a_Val">
         <eval object="MyStudent/Number" />
      </parm>
      <expr>ceil(a_Val)</expr>
   </eval>
</xout>

This code sends the following text to the output stream:
ceil = 9

chr
returns the character represented by an ASCII code value
<eval>
   <expr>chr({number})</expr>
</eval>

where:
{number} is the number which is an ASCII code value

<node name="MyStudent">
   <Name>Johnnie B. Goode</Name>
   <Number>65</Number>
</node>
<xout>chr = </xout>
<xout>
   <eval>
      <parm type="string" name="a_Val">
         <eval object="MyStudent/Number" />
      </parm>
      <expr>chr(a_Val)</expr>
   </eval>
</xout>

This code sends the following text to the output stream:
chr = A

cos
returns the cosine of a number
<eval>
   <expr>cos({number})</expr>
</eval>

where:
{number} is the number whose cosine is to be returned

<node name="MyStudent">
   <Name>Johnnie B. Goode</Name>
   <Number>0</Number>
</node>
<xout>cos = </xout>
<xout>
   <eval>
      <parm type="string" name="a_Val">
         <eval object="MyStudent/Number" />
      </parm>
      <expr>cos(a_Val)</expr>
   </eval>
</xout>

This code sends the following text to the output stream:
cos = 1

date
returns the date from a string
<eval>
   <expr>date({string})</expr>
</eval>

where:
{string} will be converted to a date

<node name="MyStudent">
   <Name>Johnnie B. Goode</Name>
   <Number>0</Number>
   <Born>10-Jan-1980</Born>
</node>
<xout>date = </xout>
<xout>
   <eval>
      <parm type="string" name="a_Val">
         <eval object="MyStudent/Born" />
      </parm>
      <expr>date(a_Val)</expr>
   </eval>
</xout>

This code sends the following text to the output stream:
date = #10-Jan-1980 00:00:00#

day
returns the day of the month from a date
<eval>
   <expr>day({date})</expr>
</eval>

where:
{date} from which the day of the month will be returned

<node name="MyStudent">
   <Name>Johnnie B. Goode</Name>
   <Number>0</Number>
   <Born>10-Jan-1980</Born>
</node>
<xout>day = </xout>
<xout>
   <eval>
      <parm type="date" name="a_Val">
         <eval object="MyStudent/Born" />
      </parm>
      <expr>day(a_Val)</expr>
   </eval>
</xout>

This code sends the following text to the output stream:
day = 10

dayofweek
returns the day of the week from a date
<eval>
   <expr>dayofweek({date})</expr>
</eval>

where:
{date} from which the day of the week will be returned

<node name="MyStudent">
   <Name>Johnnie B. Goode</Name>
   <Number>0</Number>
   <Born>10-Jan-1980</Born>
</node>
<xout>day of week = </xout>
<xout>
   <eval>
      <parm type="date" name="a_Val">
         <eval object="MyStudent/Born" />
      </parm>
      <expr>dayofweek(a_Val)</expr>
   </eval>
</xout>

This code sends the following text to the output stream:
day of week = Thursday

dayofyear
returns the day of the year from a date
<eval>
   <expr>dayofyear({date})</expr>
</eval>

where:
{date} from which the day of the year will be returned

<node name="MyStudent">
   <Name>Johnnie B. Goode</Name>
   <Number>0</Number>
   <Born>10-Jan-1980</Born>
</node>
<xout>day of year = </xout>
<xout>
   <eval>
      <parm type="date" name="a_Val">
         <eval object="MyStudent/Born" />
      </parm>
      <expr>dayofyear(a_Val)</expr>
   </eval>
</xout>

This code sends the following text to the output stream:
day of year = 143

find/instr
returns the index of the first character of a string found within another string, where the search began at a specified index position
<eval>
   <expr>find({string}, {substring}, {index})</expr>
</eval>

<eval>
   <expr>instr({string}, {substring}, {index})</expr>
</eval>

where:
{string} is the string in which the {substring} is to be found
{substring} is the string to be found in {string}
{index} is the index position within {string} where the search begins and procedes to the last character of {string}-- it is optional

<node name="MyStudent">
   <Name>Johnnie B. Goode</Name>
   <Number>0</Number>
   <Born>10-Jan-1980</Born>
</node>
<xout>find = </xout>
<xout>
   <eval>
      <parm type="string" name="a_Str">
         <eval object="MyStudent/Name" />
      </parm>
      <parm type="string" name="a_Sub">Good</parm>
      <expr>find(a_Str, a_Sub, 0)</expr>
   </eval>
</xout>
<xout>\r\n2nd find = </xout>
<xout>
   <eval>
      <parm type="string" name="a_Str">
         <eval object="MyStudent/Name" />
      </parm>
      <parm type="string" name="a_Sub">Good</parm>
      <expr>find(a_Str, a_Sub, 12)</expr>
   </eval>
</xout>

This code sends the following text to the output stream:
find = 11
2nd find = -1

floor
returns the nearest whole number smaller than the numerical argument
<eval>
   <expr>floor({number})</expr>
</eval>

where:
{number} is the real number whose floor is to be found

<node name="MyStudent">
   <Name>Johnnie B. Goode</Name>
   <Number>8.5</Number>
</node>
<xout>floor = </xout>
<xout>
   <eval>
      <parm type="string" name="a_Val">
         <eval object="MyStudent/Number" />
      </parm>
      <expr>floor(a_Val)</expr>
   </eval>
</xout>

This code sends the following text to the output stream:
floor = 8

format
returns a string of a formatted date or number
<eval>
   <expr>format({date}, {format string})</expr>
</eval>

<eval>
   <expr>format({number}, {format string})</expr>
</eval>

where:
{date} is the date that will be formatted {number} is the number that will be formatted {format string} is the string that contains the formatting expression

For details on the format strings for dates click here.
For details on the format strings for numbers click here.

<node name="MyStudent">
   <Name>Johnnie B. Goode</Name>
   <Number>27.37</Number>
   <Born>10-Jan-1980</Born>
   <LastUpd>24-May-2002 18:56:31</LastUpd>
</node>
<xout>format number = </xout>
<xout>
   <eval>
      <parm type="float" name="a_Val">
         <eval object="MyStudent/Number" />
      </parm>
      <expr>format(a_Val, "999.9")</expr>
   </eval>
</xout>
<xout>format date = </xout>
<xout>
   <eval>
      <parm type="date" name="a_Val">
         <eval object="MyStudent/LastUpd" />
      </parm>
      <expr>format(a_Val, "%B %d %Y")</expr>
   </eval>
</xout>

This code sends the following text to the output stream:
format number = 27.37
format date = May 24 2002

hour
returns the hour from the time portion of a date
<eval>
   <expr>hour({date})</expr>
</eval>

where:
{date} from which the hour will be returned

<node name="MyStudent">
   <Name>Johnnie B. Goode</Name>
   <Number>0</Number>
   <Born>10-Jan-1980</Born>
   <LastUpd>24-May-2002 18:56:31</LastUpd>
</node>
<xout>hour = </xout>
<xout>
   <eval>
      <parm type="date" name="a_Val">
         <eval object="MyStudent/LastUpd" />
      </parm>
      <expr>hour(a_Val)</expr>
   </eval>
</xout>

This code sends the following text to the output stream:
hour = 18

isnull
returns true if the argument evaluates to ""
<eval>
   <expr>isnull({string})</expr>
</eval>

where:
{string} to check for null value

<node name="MyStudent">
   <Name>Johnnie B. Goode</Name>
   <Number>0</Number>
   <Born>10-Jan-1980</Born>
   <LastUpd>24-May-2002 18:56:31</LastUpd>
</node>
<xout>isnull = </xout>
<xout>
   <eval>
      <parm type="string" name="a_Val">
         <eval object="MyStudent/Name" />
      </parm>
      <expr>isnull(a_Val)</expr>
   </eval>
</xout>

This code sends the following text to the output stream:
isnull = false

left
returns a specific number of characters starting from the beginning of a string
<eval>
   <expr>left({string}, {number of characters})</expr>
</eval>

where:
{string} for which to get the characters
{number of characters} is the number of characters to get from {string}

<node name="MyStudent">
   <Name>Johnnie B. Goode</Name>
   <Number>0</Number>
   <Born>10-Jan-1980</Born>
   <LastUpd>24-May-2002 18:56:31</LastUpd>
</node>
<xout>left = </xout>
<xout>
   <eval>
      <parm type="string" name="a_Val">
         <eval object="MyStudent/Name" />
      </parm>
      <expr>left(a_Val, 4)</expr>
   </eval>
</xout>

This code sends the following text to the output stream:
left = John

len
returns the number of characters in a string
<eval>
   <expr>len({string})</expr>
</eval>

where:
{string} for which to return the number of characters

<node name="MyStudent">
   <Name>Johnnie B. Goode</Name>
   <Number>0</Number>
   <Born>10-Jan-1980</Born>
   <LastUpd>24-May-2002 18:56:31</LastUpd>
</node>
<xout>len = </xout>
<xout>
   <eval>
      <parm type="string" name="a_Val">
         <eval object="MyStudent/Name" />
      </parm>
      <expr>len(a_Val)</expr>
   </eval>
</xout>

This code sends the following text to the output stream:
len = 16

lower
returns the lowercase converted version of a string
<eval>
   <expr>lower({string})</expr>
</eval>

where:
{string} for which to return the lowercase version

<node name="MyStudent">
   <Name>Johnnie B. Goode</Name>
   <Number>0</Number>
   <Born>10-Jan-1980</Born>
   <LastUpd>24-May-2002 18:56:31</LastUpd>
</node>
<xout>lower = </xout>
<xout>
   <eval>
      <parm type="string" name="a_Val">
         <eval object="MyStudent/Name" />
      </parm>
      <expr>lower(a_Val)</expr>
   </eval>
</xout>

This code sends the following text to the output stream:
lower = johnnie b. goode

ltrim
strips off the leftmost spaces before the first non-space character in a string and returns the resulting string
<eval>
   <expr>ltrim({string})</expr>
</eval>

where:
{string} for which to left-trim

<var type="string" name="MyVar">   A string   </var>
<xout>ltrim = </xout>
<xout>
   <eval>
      <parm type="string" name="str"><eval object="MyVar" /></parm>
      <expr>ltrim(str)</expr>
   </eval>
</xout>
<xout>.</xout>

This code sends the following text to the output stream:
ltrim = A string   .

mid
returns a specific number of characters starting from a specific position in a string
<eval>
   <expr>mid({string}, {position}, {number of characters})</expr>
</eval>

where:
{string} for which to get the characters
{position} is the position in the {string} from which the characters will be returned
{number of characters} is the number of characters to get from {string}-- if omitted then all the characters from {position} until the end of {string} will be returned

<node name="MyStudent">
   <Name>Johnnie B. Goode</Name>
   <Number>0</Number>
   <Born>10-Jan-1980</Born>
   <LastUpd>24-May-2002 18:56:31</LastUpd>
</node>
<xout>mid = </xout>
<xout>
   <eval>
      <parm type="string" name="a_Val">
         <eval object="MyStudent/Name" />
      </parm>
      <expr>mid(a_Val, 8, 7)</expr>
   </eval>
</xout>

This code sends the following text to the output stream:
mid = B. Good

minute
returns the minutes from the time portion of a date
<eval>
   <expr>minute({date})</expr>
</eval>

where:
{date} from which the minutes will be returned

<node name="MyStudent">
   <Name>Johnnie B. Goode</Name>
   <Number>0</Number>
   <Born>10-Jan-1980</Born>
   <LastUpd>24-May-2002 18:56:31</LastUpd>
</node>
<xout>minutes = </xout>
<xout>
   <eval>
      <parm type="date" name="a_Val">
         <eval object="MyStudent/LastUpd" />
      </parm>
      <expr>minute(a_Val)</expr>
   </eval>
</xout>

This code sends the following text to the output stream:
minutes = 56

month
returns the month from a date
<eval>
   <expr>month({date})</expr>
</eval>

where:
{date} from which the month will be returned

<node name="MyStudent">
   <Name>Johnnie B. Goode</Name>
   <Number>0</Number>
   <Born>10-Jan-1980</Born>
   <LastUpd>24-May-2002 18:56:31</LastUpd>
</node>
<xout>month = </xout>
<xout>
   <eval>
      <parm type="date" name="a_Val">
         <eval object="MyStudent/LastUpd" />
      </parm>
      <expr>month(a_Val)</expr>
   </eval>
</xout>

This code sends the following text to the output stream:
month = 5

not
returns the inversion of a boolean argument
<eval>
   <expr>not({boolean})</expr>
</eval>

where:
{boolean} is the boolean value to be inverted

<node name="MyStudent">
   <Name>Johnnie B. Goode</Name>
   <Number>0</Number>
   <Born>10-Jan-1980</Born>
   <LastUpd>24-May-2002 18:56:31</LastUpd>
   <LikesMusic>true</LikesMusic>
</node>
<xout>not = </xout>
<xout>
   <eval>
      <parm type="bool" name="a_Val">
         <eval object="MyStudent/LikesMusic" />
      </parm>
      <expr>not(a_Val)</expr>
   </eval>
</xout>

This code sends the following text to the output stream:
not = false

now
returns the current date and time
<eval>
   <expr>now()</expr>
</eval>
<xout>now = </xout>
<xout>
   <eval>
      <expr>now(a_Val)</expr>
   </eval>
</xout>

This code sends the following text to the output stream:
now = #24-May-2002 21:51:36#

replace
replaces all occurences of string A in string B with string C
<eval>
   <expr>replace({string}, {replacee}, {replacer})</expr>
</eval>

where:
{string} is the string that contains occurences of {replacee}
{replacee} is the string that is to be replaced in {string} with {replacer}
{replacer} is the string that replaces all occurences of {replacee} in {string}

<node name="MyStudent">
   <Name>Bald I. Baldwin</Name>
</node>
<xout>replace = </xout>
<xout>
   <eval>
      <parm type="string" name="a_Str">
         <eval object="MyStudent/Name" />
      </parm>
      <parm type="string" name="a_Replacee">Bald</parm>
      <parm type="string" name="a_Replacer">Gold</parm>
      <expr>replace(a_Str, a_Replacee, a_Replacer)</expr>
   </eval>
</xout>

This code sends the following text to the output stream:
replace = Gold I. Goldwin

reverse
returns the reversed version of a string
<eval>
   <expr>reverse({string})</expr>
</eval>

where:
{string} to be reversed

<node name="MyStudent">
   <Name>Johnnie B. Goode</Name>
   <Number>0</Number>
   <Born>10-Jan-1980</Born>
   <LastUpd>24-May-2002 18:56:31</LastUpd>
</node>
<xout>reverse = </xout>
<xout>
   <eval>
      <parm type="string" name="a_Val">
         <eval object="MyStudent/Name" />
      </parm>
      <expr>reverse(a_Val)</expr>
   </eval>
</xout>

This code sends the following text to the output stream:
reverse = edooG .B einnhoJ

right
returns a specific number of characters starting from the end of a string
<eval>
   <expr>right({string}, {number of characters})</expr>
</eval>

where:
{string} for which to get the characters
{number of characters} is the number of characters to get from {string}

<node name="MyStudent">
   <Name>Johnnie B. Goode</Name>
   <Number>0</Number>
   <Born>10-Jan-1980</Born>
   <LastUpd>24-May-2002 18:56:31</LastUpd>
</node>
<xout>right = </xout>
<xout>
   <eval>
      <parm type="string" name="a_Val">
         <eval object="MyStudent/Name" />
      </parm>
      <expr>right(a_Val, 5)</expr>
   </eval>
</xout>

This code sends the following text to the output stream:
right = Goode

round
returns the rounded version of a number
<eval>
   <expr>round({number}, {dec places})</expr>
</eval>

where:
{number} to be rounded
{dec places} is the number of decimal places to round {number} to

<node name="MyStudent">
   <Name>Johnnie B. Goode</Name>
   <Number>27.06</Number>
   <Born>10-Jan-1980</Born>
   <LastUpd>24-May-2002 18:56:31</LastUpd>
</node>
<xout>round = </xout>
<xout>
   <eval>
      <parm type="double" name="a_Val">
         <eval object="MyStudent/Number" />
      </parm>
      <expr>round(a_Val, 1)</expr>
   </eval>
</xout>

This code sends the following text to the output stream:
round = 27.1

rtrim
strips off the rightmost spaces after the last non-space character in a string and returns the resulting string
<eval>
   <expr>rtrim({string})</expr>
</eval>

where:
{string} for which to right-trim

<var type="string" name="MyVar">   A string   </var>
<xout>rtrim = </xout>
<xout>
   <eval>
      <parm type="string" name="str"><eval object="MyVar" /></parm>
      <expr>rtrim(str)</expr>
   </eval>
</xout>
<xout>.</xout>

This code sends the following text to the output stream:
rtrim =    A string.

second
returns the seconds from the time portion of a date
<eval>
   <expr>second({date})</expr>
</eval>

where:
{date} from which the seconds will be returned

<node name="MyStudent">
   <Name>Johnnie B. Goode</Name>
   <Number>0</Number>
   <Born>10-Jan-1980</Born>
   <LastUpd>24-May-2002 18:56:31</LastUpd>
</node>
<xout>seconds = </xout>
<xout>
   <eval>
      <parm type="date" name="a_Val">
         <eval object="MyStudent/LastUpd" />
      </parm>
      <expr>second(a_Val)</expr>
   </eval>
</xout>

This code sends the following text to the output stream:
seconds = 31

sin
returns the sine of a number
<eval>
   <expr>sin({number})</expr>
</eval>

where:
{number} is the number whose sine is to be returned

<node name="MyStudent">
   <Name>Johnnie B. Goode</Name>
   <Number>0</Number>
</node>
<xout>sin = </xout>
<xout>
   <eval>
      <parm type="string" name="a_Val">
         <eval object="MyStudent/Number" />
      </parm>
      <expr>sin(a_Val)</expr>
   </eval>
</xout>

This code sends the following text to the output stream:
sin = 0

tan
returns the tangent of a number
<eval>
   <expr>tan({number})</expr>
</eval>

where:
{number} is the number whose tangent is to be returned

<node name="MyStudent">
   <Name>Johnnie B. Goode</Name>
   <Number>0</Number>
</node>
<xout>tan = </xout>
<xout>
   <eval>
      <parm type="string" name="a_Val">
         <eval object="MyStudent/Number" />
      </parm>
      <expr>tan(a_Val)</expr>
   </eval>
</xout>

This code sends the following text to the output stream:
tan = 0

today
returns the current date without the time portion
<eval>
   <expr>today()</expr>
</eval>
<xout>today = </xout>
<xout>
   <eval>
      <expr>today(a_Val)</expr>
   </eval>
</xout>

This code sends the following text to the output stream:
today = #24-May-2002#

trunc/truncate
returns the date portion of a date with the time portion set to midnight
<eval>
   <expr>trunc({datetime})</expr>
</eval>

<eval>
   <expr>truncate({datetime})</expr>
</eval>

where:
{datetime} whose time portion is set to midnight

<node name="MyStudent">
   <Name>Johnnie B. Goode</Name>
   <Number>27.06</Number>
   <Born>10-Jan-1980</Born>
   <LastUpd>24-May-2002 18:56:31</LastUpd>
</node>
<xout>trunc = </xout>
<xout>
   <eval>
      <parm type="date" name="a_Val">
         <eval object="MyStudent/LastUpd" />
      </parm>
      <expr>trunc(a_Val)</expr>
   </eval>
</xout>

This code sends the following text to the output stream:
trunc = #24-May-2002 00:00:00#

upper
returns the uppercase converted version of a string
<eval>
   <expr>upper({string})</expr>
</eval>

where:
{string} for which to return the uppercase version

<node name="MyStudent">
   <Name>Johnnie B. Goode</Name>
   <Number>0</Number>
   <Born>10-Jan-1980</Born>
   <LastUpd>24-May-2002 18:56:31</LastUpd>
</node>
<xout>upper = </xout>
<xout>
   <eval>
      <parm type="string" name="a_Val">
         <eval object="MyStudent/Name" />
      </parm>
      <expr>upper(a_Val)</expr>
   </eval>
</xout>

This code sends the following text to the output stream:
upper = JOHNNIE B. GOODE

year
returns the year from a date
<eval>
   <expr>year({date})</expr>
</eval>

where:
{date} from which the year will be returned

<node name="MyStudent">
   <Name>Johnnie B. Goode</Name>
   <Number>0</Number>
   <Born>10-Jan-1980</Born>
   <LastUpd>24-May-2002 18:56:31</LastUpd>
</node>
<xout>year = </xout>
<xout>
   <eval>
      <parm type="date" name="a_Val">
         <eval object="MyStudent/LastUpd" />
      </parm>
      <expr>year(a_Val)</expr>
   </eval>
</xout>

This code sends the following text to the output stream:
year = 2002