PowerBASIC Information Center Tutorials
These tutorials were written to help you get a quick, but thorough, understanding of PowerBASIC - the scope of the language as well as it's specific capabilities.

Introduction       Projects       Language           Messages       Functions           Advanced
  • Overview
  • Examples
  • IDE
  • Compilation
  • Distribution
  • Project Files
  • DDT Windows
  • Controls
  • Menus
  • Dialogs  
  • Help Files
  • Resources  
  • Templates  
  • Project Shell  
  • Syntax
  • Operators
  • Data Types
  • Variables
  • Scope
  • Declarations  
  • Procedures
  • Flow Control
  • Windows
  • Messages
  • Callbacks
  • Mouse
  • Keyboard
  • Dialogs
  • Controls
  • Subclassing
  • Arithmetic
  • Trig  
  • Strings
  • Arrays
  • Date/Time
  • Printing
  • Files
  • Folders
  • Keyboard
  • Mouse
  • Sound
  • System
  • Error Traps
  • Debugging
  • Objects
  • Graphics
  • Databases
  • API
  • DLLs
  • ASM
  • Threads
  • Variables
    Variables are simply names used in a program, where the names represent stored numeric or string values. When an expression contains a variable, such as the expression (x+2), PowerBASIC replaces the variable with its value and computes the value of the expression, as demonstrated in the following example.

        x = 2        'x is a variable that is given the value of 2
        y = x + 2    'y is a variable whose value is now 2 + 2 = 4
    

    AS the example shows, variable values can be changed at any time during the program.

    Variable Declaration
    Declaration of a variable before using it is not required, although a compiler directive #DIM ALL can be added to a program's source code to have the compiler require variable declaration prior to use. It is considered good programming practice to require variable declaration.

    Here's an example of a simple variable declaration, using the DIM statement.

        #DIM ALL          'forces use of DIM to define variables before use
        DIM x as Single   'variable x defined as single precision number
        DIM j As Long     'variable j defines as long integer
        x = 2.3           'without DIM statements, this line causes an error
        j = 5             'without DIM statements, this line causes an error
    

    The other declaration statements, REDIM, LOCAL, GLOBAL, STATIC, and THREADED, are discussed in the section on variable scope.

    Variable Names
    In PowerBASIC all variable names begin with a letter. Variable names can be up to 255 letter and digits,

    Note that long variable names do not affect memory storage requirements. So feel free to use descriptive names of any length to make it easy for you to read and maintain your code. Other that how much typing is involved, there is no penalty for using long variable names.

    Case Sensitivity
    PowerBASIC is not case-sensitive. The variables dog$ and DOG$ are the same variables.

    However, note that x$, x%, and x& are different variables and can coexist in a program. This is not recommended because of the visual confusion it can create.

    Creating a Variable
    Unlike some languages which require that you define a variable before using it, PowerBASIC allows you to define a variable by simply using it in a line of code.

         a$ = 5     #
         b = 2.5    #
    

    When a variable has not yet been assigned a value, PowerBASIC sets the value to undef, which is similar to NULL in other languages. The PowerBASIC defined function can test to see if a variable has been assigned a value.

    Good Variable Naming Practice
    Using variable names which describe the content of the variable is considered good practice. For example, size$ is preferred over $s.

    Programmers also use the following two common variable naming practices, both of which involve using more than one word in the variable name.

         last_index     # words separated by an underscore
         LastIndex      # capitalizing words in the variable name
    

    It is also considered good practice to use Type Specifier suffixes on variable names because it gives a visual indication of the type of data that the variable expects. This is particularly useful during program debugging. Here are the two examples from above, with integer type specifiers included.

         last_index%     # words separated by an underscore
         LastIndex%      # capitalizing words in the variable name
    

    Variable Naming Exceptions - Special Characters
    There are two exceptions to the naming rules - type specifiers and contstants. Type specifiers allow other characters as suffixes to a variable name, whereas constants use variable names with other characters as prefixes to the variable names.

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