Section 3.6
Programming In QuickBASIC
3.6 Functions
A function can be used to perform a frequently occuring calculation. We can make use
of the built in functions and we can define our own.
3.6.1 Built In Functions
These function can be used in the following ways:
PRINT <function name> (Parameters)
If numeric:
PRINT 3 * <function name> (Parameters)
The following are some of the built in functions.
ABS(num!)
|
Gives the absolute value of a number. (i.e. always converts a negative
number to positive.)
|
CINT(num!)
|
Converts a floating point number to an integer.
|
INT(num!)
|
The value of num! rounded down to the nearest whole integer value.
|
SQR(num!)
|
The square root of num!
|
SGN(num!)
|
Returns:
+1 if num! > 0
0 if num! = 0
-1 if num! < 0
|
TIMER
|
Returns the number of seconds that have elapsed since midnight.
|
TIME$
|
Returns the time in the format HH:MM:SS.
|
DATE$
|
Returns the date in the format mm/dd/yyyy.
|
RND
|
Returns a psuedo random number.
|
Due to the method used to produce these random numbers, the RND
statement
may not always produce unbiased results. Therefore the RANDOMIZE TIMER
statement
should be used at the top of the program.
3.6.2 User Defined Functions
As well as the built in functions, we can write our own.
FUNCTION <function name> (Parameters)
   - - -
   - - -
   <function name> = <value>
   - - -
   - - -
END FUNCTION
Points To Note
If you wish to write a function that returns a string then you must include a '$' at the
end of the function name.
The body of the function must include an assignment statement to give a value to the
function name.