Gambas Documentation
Application Repository
Code Snippets
Compilation & Installation
Controls pictures
Deprecated components
Developer Documentation
Development Environment Documentation
About The Best Formula In The World
Architecture details
By Reference Argument Passing
Compatibility between versions
Creating And Using Libraries
Database Datatype Mapping
Database Request Quoting
Date & time management
Dates and calendars
DBus and Gambas
Differences Between Shell And Exec
Differences From Visual Basic
Distributions & Operating Systems
Drag & Drop
DrawingArea Internal Behaviour
External functions datatype mapping
Frequently Asked Questions
Gambas Farm Server Protocol
Gambas Mailing List Netiquette
Gambas Markdown Syntax
Gambas Naming Conventions
Gambas Object Model
Gambas Scripting
Gambas Server Pages
Gambas Unit Testing
Gambas Wiki Markup Syntax
Getting Started With Gambas
Hall Of Fame
Image Management In Gambas
Including Help Comments in Source Code
Interpreter limits
Just In Time Compiler
Just In Time Compiler (old version)
Localisation and Internationalization
Mailing Lists & Forums
Naming Conventions
Network Programming
ODBC Component Documentation
PCRE Pattern Syntax
Porting from Gambas 2 to Gambas 3
Previous News
Project Directory Structure
Release Notes
Reporting a problem, a bug or a crash
Rich Text Syntax
Text highlighting definition file syntax
The Program has stopped unexpectedly by raising signal #11
Variable Naming Convention
WebPage Syntax
Web site home page
What Is Gambas?
Window & Form Management
Window Activation & Deactivation
Window Life Cycle
Error Messages
Gambas Playground
How To's
Language Index
Language Overviews
Last Changes
Search the wiki
To Do
Wiki License
Wiki Manual

Variable Naming Convention

Written by Fabien Bodard

It's simply how you give name to your variables ! What method, to make difference between two type of variables or two type of objects.

You need to adopt a convention.

If you call each variable, according to the impultion of the moment, not only you will have names that you don't remember, but you will search astute variable name at place of searching astute algorithms. A calling convention need to be automatic. In fact, two person that use the same calling convention would have the same variables name.

Most of the time, bad calling convention goes from pair with a bad code.

By default, Gambas give a default name to the widgets, like button1, textbox1, etc... and then incrementing the value when you add a new component in the IDE. But the problem with this system is that your code is really difficult to interpret or to debug...

But all is not lost at this time... i've maybe a soluce for you :-).

The hungarian convention for Gambas

The hungarian convention is a good one. You have probably seen this convention in some Microsoft Visual Basic exemples sources. I don't say it's the best one, but i've use it in some other languages php, fortran, and it got fine on Gambas.

All the users of the hungarian convention that I know have in a first time hated it. But whatever your opinion is, you will not regret having learned to read Hungarian. This convention was created by Charle Simonyi, veteran of developement at Microsoft and and Hungarian of birth. It implies that the variables comprises two parts: a basic type in small letters indicating the kind of variable, and a qualifier with initial in capital letter which distinguishes a variable of the other of the same variables. Then you can add a letter like $ at the beginning to distingish the global variables.


An integer variable that will be used to locate something

An integer variable that will be used to locate something in a file and another in a textarea

A form for save a file as...

Prefix convention for common variables types

variable type Prefix
Integer i
Float f
Boolean b
Byte bt
Short sh
Long l
Single sng
Variant v
Pointer ptr
String s
Date date
Object o

Prefixe convention for array or collection variable type

variable Type Prefix
Static array ar + type prefix
Integer[] ari
Float[] arf
Boolean][] arb
Byte][] arbt
Short[] arsh
Long[] arl
Single[] arsng
Variant[] arv
String[] ars
Date[] ardate
Object[] aro
Collection col

Special types

variable Type Prefix
File fi
Process proc

Some Component prefix example

variable Type Prefix
Form frm
TextBox txtb
TextArea txta
ListBox lstb
ComboBox cbo
Timer tmr
Button but
ToggleButton tglbut
ToolButton tbut