Many programming languages require that variables and procedures (internal and external) be declared before being used. In PowerBASIC variable declaration is optional and internal procedure declarations are created automatically by the compiler using information from the procedure source code.

With external procedures, such as those found in DLL files, an explicit declaration statement is required. The declaration defines the file where the procedure is found, the procedure name, all arguments required to call the procedure, and other information needed to use the external procedure.

Here is a summary of the PowerBASIC functions used to declare variables and procedures. The first four categories provide functions to declare program variables. The next two cover internal and external procedures, respectively.

Variable Declarations
PowerBASIC variables can be used simply by placing them in the source code. It is also possible to force declaration of variables by using the #DIM ALL compiler directive.

Use of #DIM ALL is considered good programming practice because it avoids potential execution issues which are difficult to find and correct. Most programmers use the directive.

Syntax and examples of the variable declaration functions are discussed next.

Finally, here is an example showing where each of the various variable declaration statements can be used in a PowerBASIC program. Note that the PowerBASIC compiler allows the CLASS/Sub/Function code blocks to be placed before or after the PBMain() function.


    GLOBAL/THREADED ...                         'global declarations

    Function PBMain() As Long
        DIM/REDIM/LOCAL/STATIC ...              'local declarations
    End Function

    CLASS myClass
        INSTANCE                                'local declarations
        INTERFACE myInterface
            METHOD myMethod
                DIM/REDIM/LOCAL/STATIC...       'local declarations
            END METHOD
            PROPERTY myProperty
                DIM/REDIM/LOCAL/STATIC...       'local declarations
            END PROPERTY

    SUB mySub() 
        DIM/REDIM/LOCAL/STATIC ...              'local declarations

    FUNCTION myFunction() 
        DIM/REDIM/LOCAL/STATIC ...               'local declarations

Note also that while the code that defines a CLASS is placed outside all procedures, object variable definition occurs in the same locations as all other variable types.

Internal Procedure Declaration
PowerBASIC supports several types of internal procedures, including Sub, Function, Method, Property and Macro.

Sub/Function/Macro procedures are used within a standard PowerBASIC application. Method/Property functions are used exclusively within an object.

A procedure is created by simply writing the code and enclosing it with the procedure statements. Sub..End Sub/Function..End Function/Macro..End Macro/Method..End Method/Property..End Property.

Sub/Function/Macro procedures are discussed in the tutorial section on procedures, but here are a couple of early examples.

In all of these examples, the information needed to create the procedure declaration is taken from the source code by the compiler, making it unnecessary for the programmer to explicitly declare the procedures.

    Sub Hello(m$)
        Msgbox m$
    End Sub

    Function Hello(m$) as Long
        Msgbox m$
        Function = 0
    End Function

    MACRO Pi = 3.141592654
    MACRO Degree2Radian(deg) = (deg * 0.0174533)
    MACRO Radian2Degree(rad) = (rad * 57.29578)

Method and Property procedures are dicussed in the tutorial section on objects, but here are a couple of early examples.

    Method (m$) as Long
        Method = val(m$) * 2       
    End Method

    Property (m$) as Long
        Property = val(m$) * 2
    End Property

External Procedure Declaration
PowerBASIC is able to use (compiled) procedures stored in external files. To do so, an explicit DECLARE statement is required in the PowerBASIC source code file referencing the external file and the information needed to access its stored procedures.

The use of the DECLARE statement is covered in the tutorial section on API, but here are a couple of early examples.

            (BYVAL dwFreq AS DWORD, BYVAL dwDuration AS DWORD) AS LONG

            ALIAS "GetTickCount" () AS DWORD

To make it easier for PowerBASIC programmers to use standard Windows DLLs, a file named is installed with PowerBASIC. It lists the declaration statements for a large number of Windows DLL procedures, which are called API. To use the file, simply place the following include statement in the application source code.

    #INCLUDE "WIN32API.INC"  ' Win32 declares and equates

If you have any suggestions or corrections, please let me know.