FB II Compiler

PG PRO

Debugging

Memory

System

Mathematics

Resources

Disk I/O

Windows

Controls

Menus

Mouse

Keyboard

Text

Fonts

Drawing

Sound

Clipboard

Printing

Communication

ASM

Made with FB

FB II COMPILER

Variables' scope


I do know that variables are "scoped" differently in DEF FN's than they are in LOCAL FN's, and maybe that could explain what's happening. Here's what I've discovered:

* In a LOCAL FN, the variables in the parameter list ("realx", in your case) are always local to the FN. Any other variables that appear in the FN are either local to the FN or global to the whole program.

* In a DEF FN, the variabes in the parameter list are _not_ local to the FN. They are either global to the whole program, or are "local to main" (meaning that they have the same scope as non-global variables which appear outside of FN's). If your program is set up like this:

DEF FN zoomX(realx) = (gzoomx+realx*gscalex)
:
END GLOBALS


then realx is a global variable. Likewise, if you have this:

DIM realx
:
END GLOBALS
:
DEF FN zoomX(realx) = (gzoomx+realx*gscalex)


then realx is a global variable again. If you have no END GLOBALS statement at all, or if you have END GLOBALS but realx does not appear anywhere above it, then realx is "local to main."

Similar remarks apply to _non_-parameter variables which appear in your DEF FN (in your case gzoomx and gscalex). They are either global, or are local to main, depending on where they first appear relative to END GLOBALS (if any).

Possibly you're assuming that gzoomx and gscalex are globals when they're really not (there must be an END GLOBALS somewhere under their declarations in order for them to be global). This would definitely cause the DEF FN version and the LOCAL FN version to produce different results, although I would expect the LOCAL FN to produce garbage in this case (while you say it works OK).

That's all I've got

Rick