Getting Started
Sample Programs
Code Snippets

Web Sites
More Tutorials
User Groups
Talk Shows

Progress Bar

GBIC >> PowerBASIC >> Tutorials >> Syntax

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
  • Syntax
    Like any language, PowerBASIC has rules on how the code must be written for the compiler to be able to read and execute the code. These rules are called syntax. Several examples and discussion of the rules are provided below. Other sections of the tutorial cover more details.

    The basics of PowerBASIC syntax are demonstrated in the following lines of source code. These lines were selected simply to demonstrate syntax concepts and are not numbered, although numbering is supported by PowerBASIC. Numbering is rarely used by programmers, whereas labelling is frequently used.

         Dim A as String           ' variable declaration
         Dim B as Long, b as long  ' invalid - B and b are the same variable
         Dim A, B as Long          ' without specifier, A is Single
         Dim a$                    ' $ is variable type specifier for a string
         Dim MyArray()             ' undimensioned array. resize later with REDIM
         Dim N$, N%                ' N$, N% are different variables
         REM ...                   ' any line staring with REM is a comment
         y = 4  'comment here too  ' any text after a ' is also a comment
         a$ = "Hello"              ' assignment of string to variable a$.
         x = 5.23                  ' no end-of-line character required
         a$ = _                    ' use underscore to break statement into 2 lines
                 "Goodbye"         ' 2nd line of a 2-line code
         Dim a(5)                  ' simple 6 element array (0-based)
         Dim a(5 to 9)             ' alternate way to state array bounds
         x = sin(10)               ' parentheses must enclose function arguments   
         Sub MyS ()                ' declaration of Sub, no arguments
         Sub MyS (x as long)       ' declaration of Sub, one argument
         MyS x                     ' parentheses optional to use Sub

    Lines of Code
    PowerBASIC source code consists of lines of case-sensitive code. Normally, a single statement is written on each line. However, multiple statement can be written on a single line if separated by the colon : character.

    Splitting Lines
    The compiler does not care how long a line of code it, but a programmer definitely does. PowerBASIC allows a long line of code to be split into multiple lines by using the underscore _ character. When used, the underscore must be preceded by at least one space.

    Any text to the right of a ' character is treated as a comment and is ignored during execution. Also, a line that begins in REM is also treated as a comment line.

    PowerBASIC variable names consist of letters or digits but must begin with a letter. Additionally, variable names can end with a type specifier, as discussed in the tutorial on data types. Note that a type specifier is consider part of the variable name. In particular, a$ (a string) is a different variable than a% (an integer).

    Variable Definition
    Declaration of a variable for using it is optional in PowerBASIC. A compiler direction #DIM ALL is added at to a program's source code to force the compiler to identify non-declared variables.

    Variable Type Conversion
    PowerBASIC supports a wide range of variable data types (integer, long, single, string, ...). If you DIM a variable without specifying a Type, then Single is used.

    The type specifier is part of the variable name. x$ is not the same variable as x%.

    In general, you can assign the value of a variable of one numeric data type to a variable of another numeric data type. PowerBASIC will convert numeric data types as needed.

    However, if a program tries to pass a data type to a procedure that is other than what is specified in the procedure (Sub/Function) declaration, PowerBASIC will not convert the passed argument to the data type specified in the procedure declaration (generates a compiler error).

    Strings & Quotes
    Strings must be enclosed in double quotes. PowerBASIC does not support single quotes, interpolation (replacing a variable within a string by the variable's value), or escape characters (special symbols within quotes, such a line feed or tabs).

    Parentheses () are used by PowerBASIC in several ways.

    • Enclose an expression x = (5 + 2)
    • Enclose index of array x(5)= 4
    • Enclose user-defined procedure arguments MySub (x,2,b)
    • Enclose arguments of built-in functions x = sin(10)
    • Explicitly define the operator precedence to be used in an expression. This has the practical effect of forcing a sub-expression to a value PRIOR to use, which may be significant when rounding is to occur.
    • Define replacement tokens to be used in the evaluation of a MACRO.

    Parentheses are optional on Sub procedures.

    Long Lines
    Lines with lengthy statements may be broken into several lines by using the underscore _ character.

    PowerBASIC does not support the use of curly brackets { }, nor any other character, to create blocks of code. Such usage is common to C-style programming but is not part of the syntax in BASIC languages.

    The source code contained within procedures is sometimes referred to as a block of code, but is not contained within any special character pairs.

    PowerBASIC supports both Sub and Function procedures. Procedures optionally support arguments.

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