UserGuide

Migrating from PowerBASIC

From Xojo Documentation

PowerBASIC use a language very similar to the Xojo language. You will notice that many of the commands are nearly the same, but there are differences as well.

Unfortunately, PowerBASIC appears to no longer be updated by PowerBASIC Inc with no new updates since 2012 and no further updates planned. For those that need a more modern compiler that is both similar and actively updated, Xojo is a good fit.

Xojo uses the open-source LLVM compiler to generate 64-bit builds with several optimization settings. The Xojo language is similar to BASIC, but is more advanced and fully object-oriented. Xojo has a robust layout editor so you won't have to tedously create your user interfaces in code. And lastly, Xojo supports multiple platforms. The Xojo IDE itself can run on Windows, Mac and Linux. And Xojo can create these types of native apps:

  • Desktop apps for Windows, Mac, Linux and Raspberry Pi
  • Console apps for Windows, Mac, Linux and Raspberry Pi
  • Web apps for Windows, Mac, Linux and Raspberry Pi servers
  • iOS apps for iPhones and iPads

Comparison to PowerBASIC

Based on PowerBASIC online docs from here: http://www.powerbasic.com/help/pbwin/wf_njs.htm

When first released in 1998, Xojo was originally called REALbasic, which ought to highlight the origin of its BASIC-like programming language. But even then, Xojo was more advanced that your typical BASIC.

Today Xojo is a modern, object-oriented programming language in its own right that should feel very familiar to users of PowerBASIC.

The Xojo Integrated Development Environment

Xojo utilizes a powerful, modern IDE for creating your apps. The main areas of the IDE are the Project Navigator that appears on the left and the Library/Inspector that appears on the right. In the center you'll see either the UI Layout Editor or the Code Editor. The Code Editor has full syntax highlighting with auto-complete.

The Layout Editor lets you easily create your user interfaces using drag and drop. For more information on the Xojo IDE:

  • Navigator
  • Library
  • Inspector
  • Code Editor
  • Layout Editor

Programming Language

The language syntax of PowerBASIC is very similar to Xojo. You’ll see familiar syntax for If..Then..Else, For..Next, While..Wend, Dim and many other commands. Someone who has used PowerBASIC will have no trouble understanding the Xojo programming language. Some other information about the Xojo Programming Language:

  • Strongly typed
  • Fully object-oriented
  • Uses Automated Reference Counting for memory management
  • Compiles to native machine code

These User Guide topics will also be helpful:

  • Programming Language Overview
  • Command Reference

Data Types

Although Xojo data types are not always named exactly the same as PowerBASIC data types, all the equivalent types are there. For example, Integer is equivalent to a PowerBASIC Long (for 32-bit apps) and PowerBASIC Quad (for 64-bit apps). Here is a mapping of some PowerBASIC data types to Xojo data types:

PowerBASIC Data Type Xojo Data Type
n/a Boolean
BYTE UInt8
WORD UInt16
CUR Currency
DATE$ Date class
DOUBLE Double
INTEGER Int16
LONG Int32
DWORD UInt32
QUAD Int64
SINGLE Single
STRING

WSTRING

String

Text

VARIANT Variant

Auto

You can find full details of all the data types supported by Xojo in these sections of the Reference Guide:

  • Xojo Data Types
  • Xojo Advanced Data Types

Variables and Variable Scope

Xojo is strongly typed, so all variables must have a defined type.

Related User Guide topics:

  • Variables and Constants

Operators

Xojo has arithmetic and relational operators that are equivalent to what PowerBASIC has. You can read more about them in the Reference Guide:

  • Operators
  • Operator Precedence

Error Handling Like PowerBASIC you can have both compile-time errors and runtime errors. Compile-time errors are displayed in the Errors panel when you run your project. Clicking on an error takes you to the line of code in error.

For handling runtime errors, Xojo uses something a bit more modern than ON ERROR GOTO called Exception Handling. Essentially, when a runtime error occurs, an exception is raised. Your code can "catch" the exception in order to handle the error. There is even a global event that can be used to catch any error.

Controls

Unlike PowerBASIC, Xojo uses a powerful layout editor for creating your user interface layouts. The default UI controls included with PowerBASIC are, for the most part, also included with Xojo, but Xojo also has several controls that are not included with PowerBASIC.

Here is a list of some PowerBASIC controls and their Xojo equivalents:

PowerBASIC Control Xojo Desktop Control Xojo Web Control Xojo iOS Control
BUTTON PushButton WebButton iOSButton
CHECK3STATE

CHECKBOX

CheckBox WebCheckBox iOSSwitch
COMBOBOX ComboBox n/a n/a
FRAME GroupBox WebGroupBox n/a
GRAPHIC Canvas WebCanvas iOSCanvas
IMAGE ImageWell WebImageView iOSImageView
IMGBUTTON BevelButton n/a n/a
LABEL Label WebLabel iOSLabel
LINE Line WebRectangle iOSLine
LISTBOX

LISTVIEW

ListBox WebListBox iOSTable
OPTION RadioButton WebRadioGroup n/a
PROGRESSBAR ProgressBar WebProgressBar iOSProgressBar
TAB TabPanel n/a iOSTabBar
TEXTBOX TextField

TextArea

WebTextField

WebTextArea

iOSTextField

iOSTextArea

TOOLBAR Toolbar WebToolbar iOSToolbar
TREEVIEW ListBox n/a n/a

Because Xojo is object-oriented, any of its built-in controls can be subclassed to add features or change their behavior. In addition, Xojo has ContainerControls which can be used to create your own controls by combining other controls.

Differences from PowerBASIC

A big difference is that Xojo cannot create DLLs, ActiveX controls or any kind of shared libraries. Since these are all Windows-specific technologies, they are not useful for cross-platform applications.

Xojo can access DLLs and many ActiveX controls, but using them means your application will only run on Windows and cannot be cross-platform. Of course, Xojo can easily create web applications, something VB6 cannot do.

File I/O

File input and output in VB6 uses direct, path-based access to files. This is not something that works for cross-platform applications, so Xojo consolidates all file processing into a few classes: FolderItem, TextInputStream, TextOutputStream and BinaryStream.

Data Types

Xojo is a strongly typed programming language. VB6 (and older versions) would allow you to use a variable that had not been previously declared. It would infer a type based on a special character in its name (name$ would be a String, for instance). Before trying to migrate VB6 code, you should use the OPTION EXPLICIT command to make sure that all your variables are declared.