In qb4.5, there are various restrictions on namespaces . A namespace is, simply, a set of names in which all names are unique. There are several namespaces set in place in qb4.5 for the purpose of not letting the code confuse the compiler.
These are the documented restrictions:
(1) Labels and line numbers can only be used once per program.
If the line number "1" is used in the main sub, "1" cannot be used in any other subs or functions, even though there is no access to the line "1" in the main sub from any sub/function.
(2) Subs, functions and variables share a namespace. This means that no sub may have the name of a function, no variable may have the name of a sub, etc.
This restriction is valid when considering the use of a function and a variable array:
"a" could be a variable or a function.
This prevents the compiler from guessing. However, there is no such confusion between a SUB and a function, or a SUB and a variable because they are lexically different. The compiler also does not have to guess when a function/variable is the same, if the parameters, or the amount of parameters, are different.
(3) User-defined TYPEs and stand-alone variables share a namespace if the variable uses a period. However, types and functions/subs do NOT share a namespace. It is possible to have a TYPE "a" and a function/sub "a()".
An example of a type namespace interfering with a variable namespace that produces an error:
id as INTEGER
DIM bobClone AS bobClone 'This is OK..
DIM clone AS bobClone
DIM clone.bobClone AS INTEGER 'This will generate an error.
The use of clone.bobclone as an integer is just:
clone.bobClone% = 1
The use of clone.bobclone as a TYPE is:
clone.id% = 1
The two namespaces do not cause confusion in this manner, but the modification of the type to this:
bobClone AS INTEGER
...will allow the use of "clone.bobclone% = 1", therefore causing confusion if TYPEs and regular variables had separate namespaces. To be on the safe (and sloppy) side, QB does not allow them to have the same namespaces, even if combinations such as "clone.bobclone%" weren't possible.
(4) Variables that are DIMmed as a certain type (integer, etc) take over the namespace of all other variables with the same name:
This is allowed and causes no errors:
a% = 10
a# = 10.56
a$ = "67"
As soon as "DIM a AS INTEGER" comes into the picture, it will cause an error after "a% = 10":
DIM a AS INTEGER
a% = 10
a# = 10.56 'ERROR! "Duplicate definition"
a$ = "67"