## Differences from VB

While Gambas is not intended to be a clone of Microsoft Visual Basic, it's still BASIC and there are many similarities between the two languages, and many one to one relationships between features. There are probably more similarities than differences, but you can't simply copy your VB projects over and expect them to compile under Gambas. The symbol will sometimes appear on a page in this documentation to indicate that there are notes available on how using the feature described on that page differs from accomplishing the same task in VB, to help those programmers who may be migrating to Gambas from that language.

### Non-Language-Specific Differences

- VB embeds the class code for each form object into the same file as the form definition. Gambas keeps them separate, in a `.form` and a `.class` file.

- File extensions:

VB | Gambas | Type of file
--- | --- | ---
.vbp | .project (just .project, one per directory) | Project definition file
.bas | .module | Module
.cls | .class | Class file
.frm | .form | Form definition file
.frx | (whatever you want) | Binary resource files

- Gambas projects are defined as a directory with a .project file in it, and all of the files in that directory. VB can have multiple project files in each directory and can pull the same source file from a different directory into different projects, which has its benefits and disadvantages.

- Screen measurements in VB are done in "twips", units of 1/1440 of an inch; in Gambas they're done in actual pixels.

- Form controls in Gambas programs are private by default. You can change this by going into the Project Properties dialog and checking the Make Form Controls Public checkbox.

- Prior to Gambas 0.97, the Gambas divide `/` operator returned an integer if its operands were all integers. For example, `PRINT 9 / 2` returned `4` and not `4.5` . Starting with Gambas 0.97, division works more or less the same as VB-style division, with the backslash (\) operator also available to force integer division.

- Str$(), Val(), CStr()... conversion functions behave differently. For example, Str$() and Val() use the localization settings in Gambas, whereas they don't in Visual Basic. Read the documentation carefully for more details. Note that Gambas behaviour is more logical :-).

### VB Has It, Gambas Doesn't

- You can't edit code in Break mode in Gambas; you need to end program execution first.

- In Gambas, simple datatypes (integer, string, etc.) are passed by value to procedures and functions. They cannot be passed by reference as in Visual Basic. Note that VB passes parameters by reference if you do not use its `ByVal` keyword, so be careful when you try to port a VB project. Also, the contents of object datatypes (array types, collections, objects) are always passed by reference in both languages!

- There is no such thing as a project-wide global variable in Gambas. As a workaround, consider making a class called Global and declaring your global variables as static public variables in that class, and then referring to them as Global.variablename in your project. It's still poor programming practice but at least they'll be identified as global variables whenever you use them ;)

- Unless you include `Option Explicit` in a VB module, you don't need to declare variables prior to using them. Gambas behaves as if `Option Explicit` were always turned on, which makes for much better code at the expense of a bit more work.

- There's no direct Gambas equivalent to the `Index` property of VB form controls. You can easily create arrays of controls, but you have to do it in code. There's currently no way to do it graphically. Thus, when you copy a control and paste it back on the form it came from, rather than prompting you to create a control array it automatically renames the copied control to an appropriate name.

- You can't currently create transparent labels in Gambas; the background is always opaque.

- The MouseMove event only occurs when a mouse button is depressed in Gambas. The exception is the DrawingArea control, which has a Tracking property that allows getting mouse move events even if no mouse button is pressed.

- In VB you could put two strings together with the symbol + . Because the + sign is only used for mathematical addition in Gambas, you should use & instead, when you want to add one string to another.

- If you use the print command the colon : does not work to seperate your code. You must take a new line instead.

- The print command in VB 3.0 did not make a Linefeed. If you used it to print out some text with printer.print, then text got lost. The Print Command in Gambas puts everything in one line. There is nothing lost.

- In VB you can use `Mid$()` as an instruction to cut out a substring and put in some other. In Gambas, you can not use it to assign a new substring to it. For example, in VB: `MyString = "The dog jumps": Mid$(MyString, 5, 3) = "fox"` results in `MyString = "The fox jumps"`. That does not work in Gambas. You must do things like that: `MyString = Left$(MyString, 4) & "fox" & Mid$(MyString, 8)` .

- One or more characters which are legal for use in identifiers in VB code, such as underscore ("_") are not acceptable in Gambas.

- Thankfully, in Gambas you cannot use GOTO to trap errors! Instead, use CATCH, FINALLY or TRY.

### Gambas Has It, VB Doesn't

- Unlike VB, you're not required to compile in GUI support if you want to write a Gambas command-line application. Just unselect the `gb.qt` component in Project Properties and make sure you define a Sub Main.

- Gambas has the concept of control groups, which allow you to handle events from any number of different controls with one handler subroutine. This reduces redundant code and can be used to do many of the things VB's control indexes can do, and some things that VB can't.

- Whereas VB makes it impossible to run a program synchronously and receive its output without learning how to do API calls (Shell merely launches the program in the background) Gambas allows you to do so using SHELL and EXEC, control the processes you start using the Process object, and even read from and write to them, allowing you to easily add functionality with helper applications. This makes it incredibly easy to write Gambas front-ends for almost any command-line procedure.

- You can do all of the above with Unix devices and special files as well, such as serial or parallel ports. Use the /proc filesystem to write a RAID monitor, for example, or use named pipes to get multiple channels of information from a back-end program in any other language.

- To make an odd-shaped window you just set the ME.Mask property of the current window to a picture that has transparent areas. VB requires API calls and a bit more work..

- You can create controls and menu dynamically, just by instantiating them with the NEW instruction.

- You can embed a Gambas form into another one: when you instantiate the first, specify the second as the parent.

- Controls have Enter and Leave events, which allow you to know when the mouse pointer enters a control and when it leaves it. You can use them to easily implement mouse-over effects.

- You can read data in binary files and automatically manage the endianness of its format, by using the `BIG` and `LITTLE` keyword with the OPEN instruction.

- Gambas uses UTF-8 charset internally, and so projects are fully and easily internationalizable.

- Gambas is Free Software whose development environment is written in itself, allowing you to customize it to a large degree using just your BASIC skillset.

- And many other things... Just add them as you like! :-)

### Same Functionality, Different Terminology

- End Sub/End Function: see END.

- Exit Sub/Exit Function: see RETURN. Also, rather than setting a variable with the same name as the function and then exiting the function, you can simply include the desired return value as a parameter to RETURN.

- End (end program): see QUIT.

- On Error: see TRY, CATCH and FINALLY.

- Msgbox: see Message. Normally you'd want Message.Info.

- VB's default InputBox function (pop up a dialog prompting for a value which is returned to the calling program) has no direct equivalent in Gambas yet, but see the InputBox page for a class you can download and include in your projects to serve the same purpose (and more.)

- DoEvents: see WAIT. WAIT also replaces the frequently used Windows API "sleep" function.

- Inserting Double Quotes in Strings: Rather than two consecutive double quotes as in VB, use the backslash as an escape character as in C or Perl (\").

- VScrollBar, HScrollBar: Gambas' ScrollBar replaces both of these. It automatically figures out whether you want a vertical or horizontal scrollbar based on the control's dimensions: make it wide, and you get a horizontal scrollbar; make it tall, and get a vertical one.

- Open and Save dialogs: You can use either the Qt or enhanced KDE dialogs in place of the Windows common dialog. Some of the properties are named differently and filters are specified with an String array, like this: `[ "Filter 1 (*.foo)" , "Filter 2 (*.bar)" ]`

- Validating text entry: In VB, certain events have a `Cancel` parameter you can set to prevent the event from being handled normally after your handler is done, so that for instance you can allow only letters or numbers to be typed, perform field validation, or force entry to be all upper or lower case. In Gambas, this is done by using the STOP EVENT instruction.

- Keyboard and Mouse event handlers does not take parameters. They use instead static public members of the Mouse and Key classes. For example:
  - `Mouse.X` and `Mouse.Y` for the mouse coordinates.
  - `Mouse.Left` to know if the left button is pressed.
  - `Key.Code` to get the code of a key.
  - `Key.Shift` to know if the SHIFT key is pressed.
  - ...and so on.

- In Gambas, the TIMER routine returns the number of elapsed seconds since the program start.
  - In VB, it returns the number of elapsed seconds since midnight.
  - This effects also the RANDOMIZE command.