Overview of Built-In Functions

String Functions
The ability to modify and concatenate strings is a powerful feature of many programming languages, and Basic syntax doesn't disappoint. This section breaks out the different categories of string functions and summarizes how they work. The categories are: Analyzing a String, Parsing Strings, and Manipulating Strings.Throughout this section, many of the functions listed use one or both of the arguments called compare and start.
The compare argument determines when string comparisons are supposed to be case sensitive. If compare is 0, the search is case-sensitive. If it is 1, the search is not case-sensitive.
The compare argument is optional. If it is left out, the comparison defaults to 0 (case sensitive).
The start argument tells the function to process characters starting at a specified position. Any characters that are prior to that position are ignored. This argument is optional. If it is left out, then the function is performed for the entire string.
Converting Data Types
Basic syntax is a type safe language that requires all constants and variables in the same formula to be of the same data type. It also requires you to pass constants and variables as arguments using the exact data type that the formula expects. Even though the data types in Basic syntax are fairly simple, you still have to make sure that they are compatible. Fortunately, this shouldn't cause problems because there are functions to convert between the different data types.
Conversion Function
|
Description
|
CBool(number), CBool(currency)
|
Convert to Boolean.
|
CCur(number), CCur(string)
|
Convert to Currency.
|
CDbl(currency), CDbl(string),
CDbl(boolean)
|
Convert to Number. Equivalent to ToNumber(). See the section Formatting Values for Output .
|
CStr()
|
Convert to String. Equivalent
to ToText().
|
CDate(string), CDate(year,
month, day), CDate(DateTime)
|
Convert to Date.
|
CTime(string), CTime(hour,
min, sec), CDate(DateTime)
|
Convert to Time.
|
CDateTime(string),
CDateTime(date),
CDateTime(date, time),
CDateTime(year, month,
day)
|
Convert to DateTime.
|
CDateTime(year, month,
day, hour,
min, sec)
|
Convert to DateTime.
|
ToNumber(string), ToNumber(boolean)
|
Convert to a Number.
|
ToText()
|
Convert to String. Same
as CStr().
|
IsDate(string), IsTIme(),
IsDateTime()
|
Test a string for being
a valid date/time.
|
IsNumber(string)
|
Test a string for being
a valid number.
|
ToWords(number),
ToWords(number, decimals)
|
Convert a number to its
word equivalent.
|
Demonstrate the ToWords() formula
Formula = ToWords(123.45) Result is :one hundred twenty-three 45 / 100
Formula = ToWords(123.45,1) Result is :one hundred twenty-three and 5 / 100
Math Functions
Most of these functions perform basic mathematical functionality. There are only a couple of interesting points to notice. Working with whole numbers and decimals is done numerous ways. The Fix() and Round() functions take a fractional number and truncate it to a specified number of digits. The Round() function will round up to the nearest decimal. The number of decimals to display is optional and the default is zero. The Int() function is similar to the Round() function except that it only returns the whole number and will round down to the nearest whole number.
Function Name
|
Description
|
Abs(number)
|
Return the absolute
value.
|
Fix(number,
decimals)
|
Return a number with
a specified number of significant digits.
|
Int(number), numerator
\ denominator
|
Return the integer
portion of a fractional number.
|
Pi
|
3.14...
|
Remainder(numerator,
denominator),
|
Return the remainder
of dividing the numerator by the denominator.
|
numerator Mod
denominator
|
Return the remainder
of dividing the numerator by the denominator.
|
Round(number,
decimals)
|
Round up a number
with a specified number of significant digits.
|
Sgn(number)
|
Return a number's
sign.
|
Sqr(number),
Exp(number), Log(number)
|
The standard
arithmetic functions.
|
Cos(number), Sin(number), Tan(number),
Atn(number)
|
The standard
scientific functions.
|
Examples of Truncating Decimals
Function
|
1.9
|
-1.9
|
Fix()
|
1
|
-1
|
Round()
|
2
|
-2
|
Int()
|
1
|
-2
|
Demonstrate the integer division and the Mod operator
Formula = 10 \ 3'Returns 3
Formula = 10 mod 3'Returns 1
Formula = Remainder(10, 3)'Returns 1
Post a Comment