Statements
This section describes the collection of statements offered by HB++. All statements are reserved keywords that cannot be used as variable or function names.
Declarations
Some statements allow you to declare the constituent program elements, like functions and variables. The majority of these statements behave differently depending on where they are used in the program.
Variables are declared using the Dim statement. Used in a module, it declares a global variable accessible from anywhere in the project. Used in a class module, a form or a user control, it declares a member variable which can only be accessed by qualifying the variable name with an object instance. Finally, used in a procedure, it declares a local variable which only exists and is accessible within this procedure.
Methods, functions and properties are declared respectively using the statements Sub, Function and Property. Used in a module, they declare global procedures accessible from anywhere in the project. Used in a class module, a form or a user control, they declare member procedures which can only be accessed by qualifying the variable name with an object instance. It is not possible to declare local procedures ie one procedure within another.
Events are declared using the Event statement. They can only be used in a class module, a form or a user control.
The Declare statement authorizes the declaration of functions written in C and located in a shared library or in the operating system itself. It can only be used in a module.
Finally, it is possible to declare enumerated types and constants respectively with the Enum and Const statements. Contrary to other statement declarations, their effect does not depend on the location where they are used.
Apart from those residing within a procedure, all declarations must be preceded with one of the Public, Protected or Private scope modifier keywords. These basic access rules can however be overriden by the use of the Friend statement.
Control Flow
The control flow statements allow you to control the execution of your program. In the absence of such statements, program execution will always go from left to right and top to bottom. Although some simple programs only require this one way flow, all the power in a programming language is provided by its capacity to modify at runtime the statement order with conditional branching or loops.
The Goto, Call and RaiseEvent statements carry out unconditional branching whilst the If...Then...Else and Select Case statements implement conditional branching, that is to say only when a condition is true.
Loop statements repeat as many times as necessary a block of instructions. The HB++ language provides several loop control structures: Do...Loop, While...Wend, For...Next and For Each...Next. The Exit statement ends a loop prematurely.
Finally, the On Error Goto statement allows error handling, which directs the program execution towards a special routine when an error occurs.
Compilation Options
All the compilation options are set in the "Project > Settings" dialog box with the exception of the default array base index and warning display which are set independently for each project file using the Option Base and Option Warning statements.
You can also exclude certain sections of code from the compilation using the conditional compilation statements #Const and #If...Then...#Else. This is very useful for compiling different versions of your project without modifying the source code.
Other Instructions
Some statements simply carry out an action without affecting the program flow. In this sense, they appear more like functions than statements though they have a special syntax : the Let and Set statements affect a value or an object reference respectively and the Sort...On... statement sorts array or collection elements.
Reference
The statements described in this chapter are summarized below. On each page, the syntax described uses the following typographic conventions:
For example the syntax { Public | Private } Enum indicates that the Enum keyword must be preceeded by either Public or Private.
| Statement | Description |
| #Const | Defines a conditional compiler constant. |
| #Error | Raises a user defined error. |
| #If...Then...#Else | Conditionally includes or excludes certain lines from compilation. |
| #Warning | Raises a user defined warning. |
| Call | Transfers control to a Sub procedure or Function. |
| Const | Declares a constant to use in place of a literal value. |
| DebugPrint | Displays a message in the output window of the debugger. |
| Declare | Declares an external procedure or function. |
| Dim | Declares a variable and allocates the required memory space. |
| Do...Loop | Repeats a block of code whilst a condition is true or until a condition becomes true. |
| Enum | Declares an enumerated list. |
| Event | Declares a user defined event. |
| Exit | Exits a Do...Loop, While, For...Next, For Each...Next, Sub, Function, or Property. |
| For Each...Next | Repeats a group of statements for each element in a container object, such as a Collection or an array. |
| For...Next | Repeats a block of instructions the number of times indicated. |
| Friend | Authorizes classes or modules to access Private and Protected member of the current class. |
| Function | Declare the name, the arguments and the body of a function. |
| Goto | Carries out an unconditional branch to the specified line label. |
| If...Then...Else | Allows conditional execution of statements depending on the value of a boolean expression. |
| Let | Assigns the value of an expression to a variable or a property. |
| On Error Goto | Activates or deactivates an error handling routine (deprecated). |
| Option Base | Sets the default lower limit for the array index. |
| Option Warning | Deactivates a compiler warning. |
| Private | Makes a declaration only visible from the current module. |
| Property | Declares the name, arguments and the body of a property. |
| Protected | Makes a declaration only visible from the current class and its derived classes. |
| Public | Makes a declaration visible from the whole project. |
| RaiseEvent | Raises an event. |
| ReDim | Reallocates storage space for an array. |
| Select Case | Executes one among several instruction blocks, depending on the value of an expression. |
| Set | Assigns an object reference to a variable or a property. |
| Sort...On... | Sorts array or Collection elements. |
| Static | Extends the lifetime of a variable or a procedure. |
| Stop | Software breakpoint. |
| Sub | Declares the name, arguments and the body of a Sub procedure. |
| Try...Catch... | Structured runtime error handling. |
| While...Wend | Repeats a block of statements while a condition is true. |