17.07.2013 Views

GWBASIC User's Manual

GWBASIC User's Manual

GWBASIC User's Manual

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

GW-BASIC <strong>User's</strong> Guide<br />

DEF FN Statement<br />

Purpose:<br />

To define and name a function written by the user.<br />

Syntax:<br />

DEF FNname[arguments] expression<br />

Comments:<br />

name must be a legal variable name. This name, preceded by FN, becomes the name of the<br />

function.<br />

arguments consists of those variable names in the function definition that are to be replaced<br />

when the function is called. The items in the list are separated by commas.<br />

expression is an expression that performs the operation of the function. It is limited to one<br />

statement.<br />

In the DEF FN statement, arguments serve only to define the function; they do not affect program<br />

variables that have the same name. A variable name used in a function definition may or may not<br />

appear in the argument. If it does, the value of the parameter is supplied when the function is<br />

called. Otherwise, the current value of the variable is used.<br />

The variables in the argument represent, on a one-to-one basis, the argument variables or values<br />

that are to be given in the function call.<br />

User-defined functions may be numeric or string. If a type is specified in the function name, the<br />

value of the expression is forced to that type before it is returned to the calling statement. If a type<br />

is specified in the function name and the argument type does not match, a "Type Mismatch"<br />

error occurs.<br />

A user-defined function may be defined more than once in a program by repeating the DEF FN<br />

statement.<br />

A DEF FN statement must be executed before the function it defines may be called. If a function<br />

is called before it has been defined, an "Undefined User Function" error occurs.<br />

DEF FN is illegal in the direct mode.<br />

Recursive functions are not supported in the DEF FN statement.<br />

Examples:<br />

.<br />

file:///C|/Documents%20and%20Settings/Lorenzo/Desktop/GW%20Basic/DEFFN.html (1 of 2)28/03/2004 21.29.01

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!