23 of 172
ZBasic Language Reference 16 ZX Microcontroller Family Option Library Option Library "<object-library-filename>" Default: none This option, which can only be used for native mode devices, specifies the name of an object library that should be linked in when the executable is built. Typically, this directive will appear in a declarations file that identifies the public entities contained in the library. If the specified filename does not have a path prefix, it is assumed that the specified name is relative to the directory of the module containing the directive. This option may be used in multiple modules as needed. Example Option Library "mylib.a" 2.3.2 The Definitions Section The definitions section of a ZBasic program may contain constant definitions, variable definitions, subroutine definitions and function definitions. There may be any number of each of these types of definitions and the definitions may occur in any order. It is a common practice, however, to place constant and variable definitions at the top of the definitions section followed by subroutine and function definitions. On the other hand, some programmers prefer to define the constants and variables closer to the routine or routines that use them. BasicX Compatibility Note In BasicX mode, variables and constants may not be defined following any subroutine or function. Each of these program items may be defined to be Public or Private. A public item is visible to other modules and may be referenced in the definitions contained in other modules. A private item is visible only within the module in which it is defined. Generally speaking, unless there is a specific need for an item to be public, it should be private. If you make something private and later decide that you need to reference it in another module, it is a simple matter to change the definition from private to public. Defining Constants It is often convenient to define constants that can be used in other parts of the program. Doing so generally helps clarify the purpose of the value, assuming a reasonably descriptive name is chosen, and also facilitates easier maintenance and modification of the program. The syntax for defining a constant is as follows: [Public | Private] Const <name> As <type> = <value> If neither Public nor Private is specified, the constant will be private. The <name> must be a legal identifier as described in Section 2.1. The <type> must be one of the fundamental data type names described in Section 2.2 or an Enum type (described in Section 3.2). Lastly, the <value> element must be value or an expression that has a constant value and is the same type as (or compatible with) the specified <type>. In many cases, the <value> will be a simple numeric literal like -55 or 3.14159. In the case of string constants, it may be a literal string like "Hello, world!". However, it is sometimes convenient to define a constant in terms of another constant. Consider the example below.