Locating Macros and Include files
Contents of Article
Handling #INCLUDE statements for other folders
Nested #INCLUDE statements
Introduction
As stated previously, macros are stored in the SPFLite MACROS folder, which will be
C:\Users\username\My Documents\SPFLite\MACROS
If you are writing a simple, one-file macro, that is all you need to know. If you are writing a large macro in a modular fashion, or are writing a series of related macros having code in common, you would benefit from using #INCLUDE statements to organize your macro code into smaller and more manageable pieces.
The macro engine we use, called thinBasic, allows for #INCLUDE statements. According to the thinBasic documentation, an #INCLUDE statement with no explicit path is searched for in the following order:
- the current script path
- \thinBasic\inc
- any #INCLUDEDIR paths in effect
When thinBasic is integrated into other software like SPFLite, step 2 becomes "\Program Files\SPFLite\inc". That can be a problem. Putting changeable user data under the Program Files directory is not a good idea, you may need Administrator privileges to do that. Since SPFLite has already set aside the MACROS folder, it makes more sense to be looking for included macro files there.
As such, by default, SPFLite will internally add the default \MACROS folder as if it were specified by a thinBasic #INCLUDEDIR statement. This action will handle all your INCLUDE requirements if you store all macros and include files in that folder.
Handling #INCLUDE statements for other folders
When you have macros or include files in other than the default \MACROS folder, SPFLite allows you to customize the search path for these files. A file Profile may have a MACLIB setting to specify the search paths for this particular file type.
You may specify multiple paths here to be searched. Since this could make for a very long string, and difficult to enter correctly, Instead, the MACLIB command accepts a single shorted name, that of a SET symbol. e.g. MACLIB MYPATHS1 The actual list of paths is entered as a SET value for an entry MACLIB.MYPATHS1 This means you can use SetEdit to more easily enter/edit the value.
Example: You want the search path to be C:\MySpecialFolder1 and C:\MySpecialFolder2.
You would enter SetEdit via a SET command and add a line: (Note: Folder names are separated with a semicolon)
MACLIB.SPECIAL = C:\MySpecialFolder1\;C:\MySpecialFolder2\
You would then update the Profile with a MACLIB SPECIAL command.
During Macro initialization, SPFLite will dynamically add these folders just as if you had included an #INCLUDEDIR statement for each of them within your macro.
Nested #INCLUDE statements
Like many languages, thinBasic allows #INCLUDE statements to be nested. When you do this, thinBasic itself reads those nested files. If your macros are in scattered folders, you simply have to ensure that ALL necessary folders are specified above via the MACLIB and SET symbols.