Variables: Types of variables

There are five built-in types, which allow you to store integers (whole numbers in three different ranges), floating point numbers (numbers with fractional parts or very large numbers) and strings (sequences of letters, numbers or any other character). You define a variable and its type by either:

Both methods will be shown in the examples below. When you create a variable it will have its initial value set to zero or an empty string.

The built-in types

As mentioned above, there are five built-in types. A variables type is shown by the extension after the variable name in the form <variable name>.<extension>. You only need to tell PureBasic the extension for the first time and PureBasic will remember what type the variable is. The five basic types are shown in the table below:

Type Extension Use Range
Byte b Small whole numbers -128 to +127
Word w Medium sized whole numbers -32768 to +32767
Long l (lower case 'L') Large whole numbers -2147483648 to +2147483647
Float f Numbers with fractional parts or very large numbers
String s Sequences of letters, digits or other characters (e.g. an address) Up to 65536 characters

You cannot change the type of a variable once it has been defined. The compiler will give you an error if you try to do this.

As an alternative for string variables you can use the dollar symbol ($) to indicate that it is a string. If you do this you must always use the dollar symbol after the variable name. You should not put a full stop between the variable name and the dollar symbol.