Xbasic GuideThe Xbasic Debugger

The showvar() function is useful for displaying information in the development environment. However, the showvar() function can only be used in the IDE. In an Ajax callback, showvar() is not available. This is because the Xbasic code in an Ajax callback runs on the server while the application the user interacts with runs in the browser (the client.) Popup windows created using Xbasic are not accessible in the browser. Instead, you need to use the Xbasic Debugger to debug the code.

The Xbasic Debugger provides tools for inspecting your Xbasic scripts during script execution. The debugger provides standard debugging tools, such as breakpoints, watch variables, and the ability to step line-by-line through script execution.

The Xbasic Debugger is opened using the debug() function:


This statement opens the Xbasic Debugger in the Alpha Anywhere Development Environment. Let's try it out. Copy the code below into the Interactive Window. Then, select all of the code and select "Run Selected Code" from the right-click context menu.

DIM numbers[10] AS N = FLOOR(rand()*100)
DIM numTotal AS N
FOR i = 1 to numbers.size()
    numTotal = numTotal + numbers[i]

When the script executes, the Xbasic Debugger opens.


The Xbasic Debugger has three sections: the Xbasic Script, the Call Stack, and Watch Variables. The code being executed appears in the Xbasic Script portion of the debugger. The debugger highlights the next line of code to be executed with a pale yellow background.

On the right-hand side of the debugger window is the Call Stack. The Call Stack shows you the chain of functions called outside of the current script (the parent scripts.) You can mouse over the icon to the left of each entry to see the variables at that level of the stack. Clicking on an entry shows the Xbasic code that called the function.

Along the bottom is the Watch window. Variables and expressions can be added to and inspected using the Watch window. As you walk through the Xbasic script in the debugger, variables in the Watch window are updated.

You can add variables to the Watch window by double-clicking the variable name or typing the variable into the Watch window. Double click the numbers and numTotal variables to add them to the Watch window.


Note that the value for both variables contains an error message: Variable not found. This error occurs because the variables do not exist. Click the Step button to advance the script and execute the Xbasic to create the numbers variable. Click Step again to execute the code to create the numTotal variable.

You can click the Expand/Collapse icon to expand a variable and inspect its values. For example, clicking the Expand/Collapse icon for the numbers array expands the value field, showing each entry in the array.


Clicking on one of the indexes (e.g. [3]) drills down further into the array, showing the value for that specific array element. You can use the "Set variable" icon below the Expand/Collapse icon to return to the parent object.


Add the i variable to the Watch window by typing it into the Expression box below the numTotal variable. Then, click Step to execute each line in the FOR loop. The Step tool loops through the FOR loop until the value of i is greater than numbers.size(). As you step through the loop, note that the numTotal and i variables are updated in the watch window.

You can add expressions to the watch window, as well. For example, you could add the expression numbers.size() to see what the size of the numbers array is:


The Xbasic Debugger contains the tools for stepping through each line of code. The standard debugger tools are Step, Trace, Step out, Run, Halt, and Set breakpoint/Clear breakpoint:


Executes the current statement. If the current statement is a function, executes the function without stepping into (i.e. trace) the function's implementation.


Executes the current statement. If the current statement includes any calls to functions, the debugger steps into the function.

Step out

If you are inside a function call, Step out executes the rest of the function and returns to the code that called the function.


Resumes script execution.


Terminates script execution immediately.

Set breakpoint/Clear breakpoint

Adds or removes a breakpoint to the currently selected line. The Set breakpoint/Clear breakpoint tool appears only when a line of code is selected. You can select a line by clicking on it.