UserGuide

Migrating from Visual Basic

From Xojo Documentation

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 Date 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 Asc
Chr Chr
Len Len
Left Left
Right Right
Mid Mid
Trim Trim
LCase Lowercase
UCase 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 iOS Control
PictureBox Canvas

ImageWell

WebCanvas

WebImageView

iOSCanvas

iOSImageView

Label Label WebLabel iOSLabel
TextBox TextField

TextArea

WebTextField

WebTextArea

iOSTextField

iOSTextArea

Frame GroupBox n/a n/a
CommandButton PushButton

BevelButton

WebButton iOSButton
CheckBox CheckBox WebCheckBox iOSSwitch
Listbox ListBox

PopupMenu

WebListBox

WebPopupMenu

iOSTable
HScrollBar

VScrollBar

Scrollbar WebScrollbar iOSScrollableArea
Timer Timer WebTimer Timer
Shape Oval

Rectangle

WebRectangle iOSOval

iOSRectangle

WebBrowser HTMLViewer WebHTMLViewer iOSHTMLViewer
TreeView ListBox n/a n/a
Toolbar Toolbar WebToolbar iOSToolbar
MediaPlayer MoviePlayer WebMoviePlayer HTMLViewer

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.

Visual Basic Migration Assistant

Visual Basic Migration Assistant (VBMA) is a free tool that can help you to begin migrating VB6 and VB.NET code to a Xojo desktop project. VBMA creates a Xojo project from the contents of your VB project. Specifically, it copies over forms, modules, classes and their code.

What it Does

VBMA takes the selected VB project and creates a Xojo XML project file containing the forms, modules, classes and source code from the VB project. The purpose of this tool is to get your project into Xojo so that you can work on it from a single place.

VBMA does not create a working Xojo application from VB code.

Since VB forms do not exactly match Xojo windows, VBMA maps VB controls to their equivalent Xojo controls as it migrates the project. Source code is not converted or modified in any way. The code is migrated to the Xojo project, but is completely commented out and is primarily for reference.

For Best Results

  • VB 5 and 6 and VB.NET are supported. If you are using an older version of VB, upgrade your code to a later version before attempting to use VBMA.
  • Review and try to reduce your usage of 3rd party VB controls. Not only are they not cross-platform, but not all of them work with Xojo.

Migrating a Project

When you launch VBMA, you are presented with a wizard that walks you through the process of migrating a VB project.

  • After the first screen of instructions, you select the project to migrate.
  • Select the “Import Project” button and choose your VB project file. Alternatively, you can drag individual files to the List or you can use the “Add Item” button to select individual files.
  • Specify the encoding as necessary. This is the encoding/language that was used to create the VB project. This is especially important if your VB project uses any non-English filenames.
  • Click the Next button to go to the Control Mapping screen.
  • VBMA analyzes the VB project and displays the type of controls that it is using. In the Mapping screen, you can select the Xojo control to use for each VB control.
  • You can choose to save the Control Map to a file so that you can use it again for other projects.
  • Click the Migrate button to migrate the VB project to a Xojo XML project file. You will be prompted for a location to save the file.
  • When VBMA is finished it will attempt to have Xojo open the project file.
  • With your VB project in Xojo, you can now begin work on creating a Xojo version.