Assignment 4
| |
Built in Functions
Lesson Objectives
| Numeric Functions
| Abs() - Absolute value function |
| Int() - Integer Portion function |
| Rnd() - Random function |
| Sqr() - Square Root function |
|
| String Functions
| Len() - Length of String function |
| Left() - Left of String function |
| Right() - Right of String function |
| Mid() - Middle of String function |
| InStr() - Position In String function |
|
| Assignment |
Returns a value of the same type that is passed to it specifying the absolute value of
a number.
Syntax
Abs(number)
Example:
ABS(-1) and ABS(1) both return positive 1
Returns a value of the type passed to it containing the integer portion of a number.
Syntax
Int(number)
Example:
Int(7.2344)
returns 7 or Int(2.7565) returns 2
Returns a Single containing a random number.
Syntax
Rnd
Remarks
The Rnd function returns a value less than 1 but greater than or equal to zero.
Variation:
Rnd(number)
The value of number determines how Rnd generates a random
number:
For any given initial seed, the same number sequence is generated because each successive
call to the Rnd function uses the previous number as a seed for the next number in the
sequence.
Before calling Rnd, use the Randomize statement without an argument to
initialise the random-number generator with a seed based on the system timer.
To Generate a Value in a Given Range:
Int((upperbound - lowerbound + 1) * Rnd + lowerbound)
Here, upperbound is the highest number in the range, and lowerbound is the lowest
number in the range.
Returns a Double specifying the square root of a number.
Syntax
Sqr(number)
Example:
Sqr(9) will return 3.0
Len() returns the number of memory bytes needed to hold its argument.
Syntax
Len(argument)
Example:
Len(bytAge) will return 2 if bytAge has been
declared as a byte type
Len("Hello World") will return 11 since there are
10 letters and a space character
Left() returns characters from the left side of a string.
Syntax
Left(string,integer)
Example:
Left("Hello World",7) will return Hello W
Right() returns characters from the right side of a string.
Syntax
Right(string,integer)
Example:
Right("Hello World",7) will return o World
Mid() returns characters from the middle of a string.
Syntax
Mid(string, start[,
length])
*Note* if the start value is greater than the length of the
string, null is returned. If length is not given, then Mid() returns the rests of
the string from start.
Example:
Mid("Hello World",7) will return World
Mid("Hello World",7,2) will return Wo
|
|
InStr() can determine the location of a string that is contained in another string.
Syntax
InStr([start,
]string1, string2[, compare])
Start is optional, and if omitted, search will start at the first character in
String1. If Start is an integer lesss than the length of String1,
the search begins at that position. String1 is the string being searched, String2
is the string being looked for inside String1. Compare is optional,
if omitted, the type of search will be binary. Compare may be a 0 or a 1. If compare is a
0, the search will be binary. If compare is a 1, the search will be textual,
noncase-sensitive search.
Example:
InStr("Hello World","ll") will return 3
InStr(4,"Hello World","ll") will return 0
Assignment
|