#UNIQUE metastatement

Purpose | Specify whether unique variable names are required.
Syntax | #UNIQUE VAR [ON|OFF]

Remarks

By default (#UNIQUE VAR OFF), it is possible to use the same name for more than one variable in your program. For example, you might use abc%, abc#, and abc$ in the same function using default typing defined by the Type ID character. You could even create a local variable named "counters" and a global variable also named "counters".

So, when you reference a variable name in your program, which variable is actually used? Depending upon location of the reference, the compiler chooses the variable with the smallest scope. The precedence of variable scopes is:

1- Local or Static

2- Instance

3- Global or Threaded

When #UNIQUE VAR is OFF, PowerBASIC first tries to find a LOCAL or STATIC. Next, an INSTANCE, and finally a GLOBAL or THREADED. It selects the first one it finds, in that sequence. Of course, you cannot use the same name for a LOCAL and a STATIC, unless you use a Type ID character to differentiate them. You can never use the same name for a GLOBAL and a THREADED, as it would be impossible to tell them apart. While this offers the most flexibility, it can be confusing, and can lead to the creation of insidious, hard-to-find errors in your program. When you reference the wrong variable by accident, the results can be disastrous. If #UNIQUE VAR is enabled, PowerBASIC will require that all variable names be unique. The can make your job a good deal easier, as it removes the ambiguity found with identifier reuse. There are a few exceptions to the uniqueness rule, which are designed to improve readability in your code:

1- Local, Static, and Parameter names may be reused in other Subs, Functions, and Methods.

2- Instance names may reused in other Classes.

3- Scalar and array names may co-exist if they they are the same data type and scope.

See also | #DIM, DEFtype, DIM, GLOBAL, LOCAL, REDIM, STATIC, OPTION EXPLICIT