Futurebasic/Language/Reference/local

LOCALEdit

SyntaxEdit

[CLEAR] LOCAL [MODE]

DescriptionEdit

This statement is an alternative way to indicate the beginning of the scope of a local function. If used, it must appear somewhere above the LOCAL FN statement. All non-global variables which are declared between the LOCAL statement and the LOCAL FN statement have a scope local to the function. Adding the CLEAR and/or MODEkeywords has the following additional effects:

  • The CLEAR keyword causes all of the function's local variables and arrays (except parameter-list variables) to be initialized to zeros, null strings or empty records, each time the function is called. Otherwise, the variables will have unpredictable initial values. You can accomplish the same effect by adding the CLEAR keyword to the LOCAL FN statement.
  • The MODE keyword prevents the use of global variables within the function. That is, all variables inside the function will be local variables, even those which have the same names as global variables. This is a good practice when you're writing a function that you might wish to use in a number of different projects, because it removes the possibility of the function's local variables being misinterpreted as globals.

Note:
DIM is the only kind of statement that you should put between the LOCAL statement and the LOCAL FN statement. Executable statements placed between LOCAL and LOCAL FN will never be executed.

You cannot declare any of the variables in the function's parameter list using a DIM statement after the LOCAL statement.

A compiler preference allows you to fill LOCAL FNs with $A5A5 for debugging. With this item checked, all functions that do not begin with CLEAR LOCAL have every variable filled with this value. It's a great debugging tool.

See AlsoEdit

LOCAL FN; END FN; DIM; BEGIN/END GLOBALS