Migrating from Visual Basic

VisualBasic

Visual Basic (6 or earlier) and Visual Basic .NET 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.

You can find further information in these blog posts: A Modern Alternative to Visual Basic and Migrate Your Visual Basic Apps to Xojo and the Migrating to Visual Basic video.

To help make your transition from Visual Basic easier you can also download the open-source VB library which maps many VB commands to their Xojo equivalents for you:

  • Xojo.VB: A library of Visual Basic functions for use with the Xojo programming language.

Similarities to Visual Basic

Visual Basic 6 (VB6) is no longer supported by Microsoft, which recommends you instead migrate to Visual Basic .NET (VB.NET). But Visual Basic .NET is large and complex, not to mention not cross-platform. Xojo is usually a better choice for Visual Basic 6 apps because it has the simplicity of VB6, but is a fully object-oriented language like VB.NET.

Programming language

To start with, the language syntax of VB 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 either VB6 or VB.NET will have no trouble understanding the Xojo programming language.

Data types

Although Xojo data types are not always named exactly the same as VB6 data types, all the equivalent types are there. For example, Integer is equivalent to a VB6 Long. Here is a mapping of some VB data types to Xojo data types:

VB Data Type

Xojo Data Type

Boolean

Boolean

Byte

UInt8

Currency

Currency

Date

DateTime class

Double

Double

Integer

Int16

Long

Integer

Object

Object

Single

Single

String

String

Variant

Variant

Commands

Below are some common VB commands and their corresponding Xojo commands.

String manipulation

VB Command

Xojo Command

Asc

String.Asc

Chr

String.ChrByte

Len

String.Length

Left

String.Left

Right

String.Right

Mid

String.Middle

Trim

String.Trim

LCase

String.Lowercase

UCase

String.Uppercase

Mathematical functions

VB Command

Xojo Command

Abs

Abs

Cos

Cos

Sin

Sin

Tan

Tan

Val

Val

Rnd

Rnd

Int

Floor

Input and output

VB Command

Xojo Command

MsgBox

MessageBox

Date and time

VB Command

Xojo Command

Date

DateTime

Time

DateTime

Timer

Timer

Miscellaneous

VB Command

Xojo Command

IsNull

Is Nil

File handling

VB Command

Xojo Command

Open

TextInputStream.Open, BinaryStream.Open

Controls

The default UI controls included with VB are, for the most part, also included with Xojo. But Xojo also has several controls that are not included by default with VB. Of course VB had plenty of additional, but Windows-specific, controls that could be added to its default setup and many of these controls can be added to Xojo using ActiveX, but they will also remain Windows-only.

Here is a list of some VB controls and their Xojo equivalents for desktop, web and iOS apps:

VB Control

Xojo Desktop Control

Xojo Web Control

Xojo Mobile Control

PictureBox

DesktopCanvas, DesktopImageViewer

WebCanvas, WebImageViewer

MobileCanvas MobileImageViewer

Label

DesktopLabel

WebLabel

MobileLabel

TextBox

DesktopTextField, DesktopTextArea

WebTextField, WebTextArea

MobileTextField, MobileTextArea

Frame

DesktopGroupBox

n/a

n/a

CommandButton

DesktopButton, DesktopBevelButton

WebButton

MobileButton

CheckBox

CheckBox

WebCheckBox

MobileSwitch

Listbox

DesktopListBox, DesktopPopupMenu

WebListBox, WebPopupMenu

iOSMobileTable

HScrollBar, VScrollBar

DesktopScrollbar

n/a

MobileScrollableArea

Timer

Timer

WebTimer

Timer

Shape

DesktopOval, DesktopRectangle

WebRectangle

MobileOval, MobileRectangle

WebBrowser

DesktopHTMLViewer

WebHTMLViewer

MobileHTMLViewer

TreeView

DesktopListBox

n/a

n/a

Toolbar

DesktopToolbar

WebToolbar

MobileToolbar

MediaPlayer

DesktopMoviePlayer

WebMoviePlayer

MobileHTMLViewer

Differences from Visual Basic

Xojo definitely feels familiar to VB developers, but there are differences as well. 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 apps.

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 and iOS apps, 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 apps, so Xojo consolidates all file processing into a few classes: FolderItem, TextInputStream, TextOutputStream and BinaryStream.

Data typing

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.