Danaher Motion
06/2005
BASIC Moves Development Studio
M-SS-005-03 Rev
E
39
An MC-BASIC library is an ASCII file containing only the subroutines’ and
functions’ code. The file does not have a main program part. The name of a
library file must have the extension,
.LIB
. The format of a library file is:
Declarations of static variables
{PUBLIC} SUB <
sub_name
>
{
declaration of variables local to the sub-program
}
{
sub code
}
END SUB
…
{PUBLIC} FUNCTION <
function_name
> AS <
return_type
>
{
declaration of variables local to the function-program
}
{
function code
}
END FUNCTION
…
The
Public
keyword allows a subroutine or a function to be called from
within the importing task. These subroutines and functions are visible from
outside the scope of the library. Subroutines and functions 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(…)
…
END SUB
SUB private_sub
(…)
…
END SUB
The subroutine, private_sub, can be used only inside the library (i.e., by
other subroutines and functions of the library). public_sub can be used in
any user task (program file, another library file) importing the library.
However, the same library can be imported by multiple tasks
simultaneously.
A library file is handled like any other program file. A library file can be sent
to the Flash disk, or retrieved and deleted from Flash disk. To use a library
file in a program, the library must first be loaded into memory from either the
terminal or another task.
LOAD
MyLib.lib
To unload the library, enter:
UNLOAD
MyLib.lib
If a program or library task references a subroutine or a function of 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
MyLib.lib
The syntax for calling a library subroutine or function from the importing task
is the same as the syntax for calling a local subroutine or function. There is
no need to specify which library file contains the called subroutine or
function (because a task cannot import two libraries defining subroutines or
functions with identical names).