Project 06/2005
Danaher
Motion
54 Rev
E
M-SS-005-03l
The format of a library file is:
Declaration of static variables
...Etc.
{PUBLIC}SUB <
sub_name_1
> etc…
{
Declaration of variables local to the sub-program
}
{
sub-program code
}
END SUB
…etc …
{PUBLIC} SUB <
sub_name_n
> etc…
{
Declaration of variables local to the sub-program
}
{
sub-program code
}
END SUB
The
{PUBLIC}
keyword allows a subroutine to be called from within any MC
task. These subroutines are visible from outside the scope of the library.
Sub-routines declared without the {
PUBLIC
} keyword can only be used
inside the scope of the library. They are PRIVATE library functions. For
example:
PUBLIC SUB public_sub(…etc…)
…etc…
END SUB
SUB private_sub(…etc…)
…etc…
END SUB
The subroutine “private_sub” can be used only inside the library. The
"public_sub” can be used in any program file by importing the library into it.
The scope of the library is the task that imports it. However, you can import
the library into each of multiple tasks.
A library file is used like any other program file. You can send a library file to
the Flash disk and you can retrieve it or delete it. In order to use a library file
in a program, the library must first be loaded into memory.
LOAD MyLibrary.lib
To unload the library, enter:
UNLOAD MyLibrary.lib
If a program or library task references a subroutine in a library, the program
or library task must be unloaded from memory before the library can be
unloaded.
After a library is loaded in memory, it must then be imported into a program.
IMPORT
must be placed at the beginning of the program code before any
other command or declaration.
IMPORT MyLibrary.lib
The syntax for calling a library subroutine or function from a task is the same
as the syntax for calling a local subroutine from the task. You do not need to
specify which library file contains the subroutine you want to call (because you
can not import two library files that contain the same library function name).
User-defined Functions
. MC BASIC allows you to define your own
functions to be used in programs in the same manner as using BASIC's pre-
defined functions. User-defined functions are composed with multiple lines
and are recursive (can call itself). Unlike BASIC's system functions, the
scope of user-defined functions is limited to the task in which it is defined.