# Migrating from Visual Basic

<div class="rst-class">

forsearch

</div>

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](http://blog.xojo.com/2013/06/19/a_great_alternative_to_visual_basic/) and [Migrate Your Visual Basic Apps](http://blog.xojo.com/2013/06/19/a_great_alternative_to_visual_basic/) to Xojo and the [Migrating to Visual Basic video](https://youtu.be/9d9PhFWCQC4).

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](https://github.com/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</api/language/if...then...else>`, `For...Next</api/language/loops/for...next>`, `While...Wend</api/language/loops/while...wend>`, `Dim</api/language/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</api/data_types/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</api/data_types/boolean>`                |
| Byte         | `UInt8</api/data_types/additional_types/uint8>`   |
| Currency     | `Currency</api/data_types/currency>`              |
| Date         | `DateTime</api/data_types/datetime>` class        |
| Double       | `Double</api/data_types/double>`                  |
| Integer      | `Int16</api/data_types/additional_types/int16>`   |
| Long         | `Integer</api/data_types/integer>`                |
| Object       | `Object</api/data_types/additional_types/object>` |
| Single       | `Single</api/data_types/single>`                  |
| String       | `String</api/data_types/string>`                  |
| Variant      | `Variant</api/data_types/variant>`                |

### Commands

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

#### String manipulation

| VB Command | Xojo Command                         |
|------------|--------------------------------------|
| Asc        | `String.Asc<string.asc>`             |
| Chr        | `String.ChrByte<string.chrbyte>`     |
| Len        | `String.Length<string.length>`       |
| Left       | `String.Left<string.left>`           |
| Right      | `String.Right<string.right>`         |
| Mid        | `String.Middle<string.middle>`       |
| Trim       | `String.Trim<string.trim>`           |
| LCase      | `String.Lowercase<string.lowercase>` |
| UCase      | `String.Uppercase<string.uppercase>` |

#### Mathematical functions

| VB Command | Xojo Command             |
|------------|--------------------------|
| Abs        | `Abs</api/math/abs>`     |
| Cos        | `Cos</api/math/cos>`     |
| Sin        | `Sin</api/math/sin>`     |
| Tan        | `Tan</api/math/tan>`     |
| Val        | `Val</api/text/val>`     |
| Rnd        | `Rnd</api/math/rnd>`     |
| Int        | `Floor</api/math/floor>` |

#### Input and output

| VB Command | Xojo Command                                 |
|------------|----------------------------------------------|
| MsgBox     | `MessageBox</api/user_interface/messagebox>` |

#### Date and time

| VB Command | Xojo Command                         |
|------------|--------------------------------------|
| Date       | `DateTime</api/data_types/datetime>` |
| Time       | `DateTime</api/data_types/datetime>` |
| Timer      | `Timer</api/language/timer>`         |

#### Miscellaneous

| VB Command | Xojo Command                                                         |
|------------|----------------------------------------------------------------------|
| IsNull     | `Is</api/language/operators/comparison/is>` `Nil</api/language/nil>` |

#### File handling

| VB Command | Xojo Command                                                                         |
|------------|--------------------------------------------------------------------------------------|
| Open       | `TextInputStream.Open<textinputstream.open>`, `BinaryStream.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</api/user_interface/desktop/desktopcanvas>`, `DesktopImageViewer</api/user_interface/desktop/desktopimageviewer>` | `WebCanvas</api/user_interface/web/webcanvas>`, `WebImageViewer</api/user_interface/web/webimageviewer>` | `MobileCanvas</api/user_interface/mobile/mobilecanvas>` `MobileImageViewer</api/user_interface/mobile/mobileimageviewer>`  |
| Label                                | `DesktopLabel</api/user_interface/desktop/desktoplabel>`                                                                         | `WebLabel</api/user_interface/web/weblabel>`                                                             | `MobileLabel</api/user_interface/mobile/mobilelabel>`                                                                      |
| TextBox                              | `DesktopTextField</api/user_interface/desktop/desktoptextfield>`, `DesktopTextArea</api/user_interface/desktop/desktoptextarea>` | `WebTextField</api/user_interface/web/webtextfield>`, `WebTextArea</api/user_interface/web/webtextarea>` | `MobileTextField</api/user_interface/mobile/mobiletextfield>`, `MobileTextArea</api/user_interface/mobile/mobiletextarea>` |
| Frame                                | `DesktopGroupBox</api/user_interface/desktop/desktopgroupbox>`                                                                   | n/a                                                                                                      | n/a                                                                                                                        |
| CommandButton                        | `DesktopButton</api/user_interface/desktop/desktopbutton>`, `DesktopBevelButton</api/user_interface/desktop/desktopbevelbutton>` | `WebButton</api/user_interface/web/webbutton>`                                                           | `MobileButton</api/user_interface/mobile/mobilebutton>`                                                                    |
| CheckBox                             | `CheckBox</api/user_interface/desktop/desktopcheckbox>`                                                                          | `WebCheckBox</api/user_interface/web/webcheckbox>`                                                       | `MobileSwitch</api/user_interface/mobile/mobileswitch>`                                                                    |
| Listbox                              | `DesktopListBox</api/user_interface/desktop/desktoplistbox>`, `DesktopPopupMenu</api/user_interface/desktop/desktoppopupmenu>`   | `WebListBox</api/user_interface/web/weblistbox>`, `WebPopupMenu</api/user_interface/web/webpopupmenu>`   | `iOSMobileTable</api/ios/iosmobiletable>`                                                                                  |
| HScrollBar, VScrollBar               | `DesktopScrollbar</api/user_interface/desktop/desktopscrollbar>`                                                                 | n/a                                                                                                      | `MobileScrollableArea</api/user_interface/mobile/mobilescrollablearea>`                                                    |
| Timer                                | `Timer</api/language/timer>`                                                                                                     | `WebTimer</api/web/webtimer>`                                                                            | `Timer</api/language/timer>`                                                                                               |
| <span class="title-ref">Shape</span> | `DesktopOval</api/user_interface/desktop/desktopoval>`, `DesktopRectangle</api/user_interface/desktop/desktoprectangle>`         | `WebRectangle</api/user_interface/web/webrectangle>`                                                     | `MobileOval</api/user_interface/mobile/mobileoval>`, `MobileRectangle</api/user_interface/mobile/mobilerectangle>`         |
| WebBrowser                           | `DesktopHTMLViewer</api/user_interface/desktop/desktophtmlviewer>`                                                               | `WebHTMLViewer</api/user_interface/web/webhtmlviewer>`                                                   | `MobileHTMLViewer</api/user_interface/mobile/mobilehtmlviewer>`                                                            |
| TreeView                             | `DesktopListBox</api/user_interface/desktop/desktoplistbox>`                                                                     | n/a                                                                                                      | n/a                                                                                                                        |
| Toolbar                              | `DesktopToolbar</api/user_interface/desktop/desktoptoolbar>`                                                                     | `WebToolbar</api/user_interface/web/webtoolbar>`                                                         | `MobileToolbar</api/user_interface/mobile/mobiletoolbar>`                                                                  |
| MediaPlayer                          | `DesktopMoviePlayer</api/user_interface/desktop/desktopmovieplayer>`                                                             | `WebMoviePlayer</api/user_interface/web/webmovieplayer>`                                                 | `MobileHTMLViewer</api/user_interface/mobile/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</api/files/folderitem>`, `TextInputStream</api/files/textinputstream>`, `TextOutputStream</api/files/textoutputstream>` and `BinaryStream</api/files/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.

<div class="seealso">

[Xojo blog posts about Visual Basic](https://blog.xojo.com/tag/visual-basic/)

</div>
