Xbasic Language Reference


An Xbasic script's structure and flow of execution is determined by command statements. Command statements declare user-defined functions and variables, perform or stop a repeated action, or conditionally choose among two or more steps.


You can add comments to Xbasic by starting a line with an apostrophe.


The .T. operator assigns the value of TRUE to an expression or variable.


The .F. operator assigns the value of FALSE to an expression or variable.


Assigns the value of an expression to a variable


The DEFINE CLASS ... END CLASS language elements create a new class. The class may DIM and assign values to variables. It may also include functions (methods).

DIM ... AS

DIM is used to declare, allocate, and optionally initialize a variable.


Way to override the default assignment. If you say DIM num as N = default 2 it will set your default value to 2.

Xbasic Arrays

To store a series of data values of the same data type together under the same variable name, declare the variable as an array. Arrays are useful for collecting and processing lists of information. They must be explicitly defined with the DIM statement before they are used. The declaration must include the Array Size which is the maximum number of data elements the array will contain.


Defines an Xbasic structure.


CONSTANT declares a constant variable. The constant variable's value is set when the constant is declared. The value may never be changed. While a constant variable cannot be changed, it can be deleted. See the examples below.


REDIM is used to change the size of an array.


A Namespace is a collection of data types. Data types are organized into 5 groups.

Null Table Field Values

Alpha Anywhere does not really have the concept of a NULL value for a table field value. If you want to test if the field is empty, then you use these expressions:


<<%DELIMITER% ... %DELIMITER% allows you to define a quoted character string. This command is typically used when the string includes carriage return-line feed characters (CR-LF).


DELETE deletes Variable_Name. You can specify an optional scope in order to explicitly define the variable to be deleted.

Operators in Xbasic

Operators are used to write logical, arithmetic, character, date, time, and comparison expressions in Xbasic.

IF ... THEN ... ELSE

Executes the statements for the first logical expression that evaluates to TRUE.


Conditional control structure comprised of one or more CASE statements.


Creates a for loop wherein parts of the loop can be skipped, using 'continue'.


Repeats a series of Xbasic statements a specified number of times.


The FOR EACH ... NEXT operators allow you to step through a list, collection, or array without knowing the number of elements that it contains.


Repeats the statements it contains while the Logical Expression evaluates to TRUE


Allows you to manipulate and define variables in a specified variable name space, or for a specified "dot" variable.


EXIT provides an alternative way to leave a loop or function construct before the NEXT, end FUNCTION, or end while statements are reached.


Used to declare a user-defined function.

User-Defined Functions

It is also possible to define and use functions of your own.


The END statement stops script execution; closes all files, indexes, and tables opened by the script; and removes all local variables.


RETURN causes an unconditional exit from a user-defined function and return a value.


UNDECLARE removes an externally defined function (for example a Windows API function).


Causes the execution of a script to skip to the line after the specified label.

Handling Errors

An important part of writing any program is handling potential errors properly. You should do the same when writing an Xbasic script, making sure it can recover from some common run-time errors (e.g., when a file is not found, the disk is full, or the table is opened exclusively by another session or user).


Expects to have the error handled


RESUME is used at the end of an error-handling routine to resume program execution.


Suspends the execution of a script.


Opens a split window that lets you play around with graphics in the Interactive window. This is an older command that was useful for desktop applications. With newer applications you might want to consider using SVG.


Used to specify various Xbasic options.


PARENT is an alias for the parent of an object. Unlike PARENTFORM and TOPPARENT, this alias does not have to refer to a form or browse.


PARENTFORM is an alias for the form or browse that contains an object.


An alias for the top-most form or browse.


An alias for the current object.


Allow a foreground thread to run via a background thread.

<%A5 ? ... %>

The <%A5 ? ... %> construct is used to insert Xbasic code into an .A5W page, that the Application Server will subsequently process.


Loads a file named in expression, preprocesses it as an A5W page, parses and executes it, and adds it to the packages for the current script.


The name of an Xbasic script in which multiple functions are declared.

Argument_List Data Structure

The Argument_List data structure is a comma delimited list in the format:

Automating Your Alpha Anywhere Applications

Alpha Anywhere's programming language is called Xbasic. Xbasic allows you to build powerful, highly customized database applications. Xbasic is an extremely rich language with hundreds of methods and functions.

Class Attribute Keywords

Alpha Five Version 7 honors only the static keyword. Eventually, Alpha Anywhere will eventually honor others keywords, such as private. A good way to describe the static attribute is to look at the documentation for Xbasic methods.

Class Scope Keywords

Several keywords are useful for working with scripts.


Alpha Anywhere allows users to create their own classes. The class creation syntax is as follows.

Code Indirection

Code indirection refers to the situation when you want to execute an Xbasic command that is contained in a variable (i.e. to indirectly execute an Xbasic command).


A collection is an Xbasic datatype, similar to an array, but whose elements are referenced with a "key" rather than an index. A key is a value (character, numeric or date) that uniquely identifies an element in a collection.

Command Statements

The Xbasic command statements determine the structure and flow of execution in a script. For example, the if .. then statement is used to perform actions conditionally. The following script will make the computer beep if the supplied logical expression, x < 5, evaluates to .T. (TRUE):

Compiling the Script

Before a script is run, it must be compiled. When a script is compiled, the Xbasic syntax you have written is checked and then turned into a series of compact machine instructions.

Defining a Function with Optional Pointer Variables

To define a function with an optional pointer variable, you must follow the function declaration syntax illustrated below. The parameter = value portion of the declaration is how a default value is defined. NULL_VALUE() is used to assign a NULL value to a pointer.

Expression Components

An expression can include any combination of fields, constants, operators, and functions. Refer to the following subsections for more information about how each is used in an expression.

Getting the Name of the Currently Running Script or Function

The following script illustrates how to get the name of the currently running script or function.

Modifying Object Event Code on the Fly

Using Xbasic, you can access and modify the scripts that are attached to object events. To view the script that is attached to an object event, use the object's Code property. For example, assume that you have a form called "Customer" with a button called "Button1". To see the Xbasic script that is attached to the button's OnPush event, type this command in the Interactive window:

Quoted Xbasic Statement

A quoted Xbasic statement is one where all parts of the statement, except variables, are quoted. You will need to use quoted Xbasic statements with the EVAL() and EVAL_VALID() functions.

Reserved Words

A list of reserved words that apply across Alpha Anywhere's applications.

Variable Data Types

Xbasic provides built-in data types for declaring variables, functions, and making working with SQL and DBF data easier.

Xbasic Reference

Additional guides for using Xbasic


For internal use only.


DECLARE declares an externally defined function (for example a Windows API function).


The DECLARESTRUCT command provides a means of representing structures ( 'struct' for those who know C, RECORD to those familiar with Pascal, and TYPE for those who know Visual Basic) .