Amos Professional Manual  Contents  Index

Procedures


Because the global variables cannot be accessed from inside the procedure, the procedure assigns a value of zero to them no mater what value they are given globally.

E> A=666 : B=999
   EXAMPLE
   Print A,B
   Procedure EXAMPLE
    Print A,B
   End Proc

To avoid errors, you must treat procedures as separate programs with their own sets of variables and instructions. So it is very bad practice for the AMOS Professional programmer to use the same variable names inside and outside a procedure, because you might well be confused into believing that completely different variables were the same, and tracking down mistakes would become a nightmare. To make life easy, there are simple methods to overcome such problems.

One method is to define a list of parameters in a procedure. This creates a group of local variables that can be loaded directly from the main program. For example:

E> Procedure HELLO[NAME$]
    Print "Hello ";NAME$
   End Proc
   Rem Load N$ into NAME$ and enter procedure
   Input "What is your name?",N$
   HELLO[N$]
   Rem Load string into NAME$ and call HELLO
   HELLO["nice to meet you!]

Note that the values to be loaded into NAME$ are entered between square brackets as part of the procedure call. This system works equally well with constants as well as variables, but although you are allowed to transfer integer, real or string variables, you may not transfer arrays by this method. If you need to enter more than one parameter, the variables must be separated by commas, like this:

X> Procedure TWINS[A,B]
   Procedure TRIPLETS[X$,Y$,Z$]

Those procedures could be called like this:

X> TWINS[6,9]
   TRIPLETS["Xenon","Yak","Zygote"]

SHARED
structure: define a list of global variables
Shared list of variables

Back    Next
05.05.05