BeginningSFBasic

Module Options

Many Swordfish modules are configured at compile time using options. For example,

#option LCD_RS = PORTE.0

Make sure that the #option is declared before the module is included. If you declare the option after the include file, it will be ignored.

Strings

When declaring strings, don't forget to allow enough space for the null terminator. For example, if you want to declare a 3 character string, you need to use

 dim MyStr as string(4) 

If you don't explicitly give a string dimension, Swordfish defaults to 24. That is, 23 characters plus a null terminator.

Variables

Public or Private?

With in SwordFish a variable can be thought of in 2 states Static (Public) eg will not be touched by the compiler, or recycled (Private) where once the Function/Sub has finished it will be recycled for use by other routines.

Not quite correct...

It's better to think in terms of scope. A module level variable (that is, a variable not declared in a sub or function) is static, but it can be public or private. Every sub or function within a module can see a module level variable - even if it is private (and assuming it is declared before it is referenced). However, if you import a module into another module or program, only public variables can be seen. In programming terms, public subroutines, functions and variables are the modules 'interface'

Variables declared withing a subroutine or function are of course private to the routine they are declared in - referred to as 'local'. Parameters are local in terms of scope. For example, you cannot reference a parameter by name outside the procedure it is declared in. However, parameters do provide the 'interface' to a sub or function.

All 'local' variables (parameters and variables) are recycled by the compiler. Module level variables (private or public) are not recycled and are static.

Hope the above is useful...

David Barker

To understand how you the variable you declared is seen by the compiler you have to think of the different context the compiler sees the variable in.

1 Main, this is with in the main program i.e not with in a Module or a Function/Sub Variables declared here................

To be continued once I get my facts right

Please correct add to this section by editing it, just click the Edit button below