User Tools

Site Tools


7.0 Data types - Overview

Data types are required if you want to store data - as character-bound information - in a variable. Describe data types:

  • what kind of data can be stored in a variable,
  • the range of values that a certain data type covers,
  • the permitted operations for the selected data type and
  • the representation of the data in the memory, which determines how much memory is made available for a variable of a certain type.

There are native data types in Gambas. These include, for example, data types with the names (keyword), integer, byte, string or float. An overview of the native data types can be found in table 7.0.1 The syntax of a structure has been introduced in Gambas 3. These structures allow you to combine logically relevant IT units (both data types and classes or objects) into a new unit - a structure. However, this structure has no methods or events. Of particular importance in Gambas as an object-oriented language are the classes. Anything that is not a data type, structure, or executable code is a class. They are characterised by the fact that they are a logical encapsulation of properties, methods and events. An instance of a class is called an object.


  • Gambas has native data types that carry their value information according to their type. The system checks whether the value assigned to a variable or constant collides with the declared data type.
  • The structures are a bundling of different but related value information.
  • In addition to the information (properties), classes also have methods to modify them and events to interactively act.

Thus, structures take a mediatingposition between the native data types and the abstract classes (concrete and abstract in the sense of their definition).

Data Type Description Default Memory Size
Boolean TRUE or FALSE FALSE 1 Byte
Byte 0… 255 0 1 Byte
Short -32.768… +32.767 0 2 Bytes
Integer -2.147.483.648… +2.147.483.647 0 4 Bytes
Long -9,223,372,036,854,775,808…. 9,223,372,036,854,775,807 0 8 bytes
Single Like the float-data type in C 0.0 4 Bytes
Float Like the double data type in C 0.0 8 bytes
Date Date and time, each stored in an integer value ZERO 8 bytes
String A variable-length string with variable length ZERO 4 bytes
Variant Every data type ZERO 12 bytes
Object Anonymous reference to an object ZERO 4 bytes
Pointer Pointer to a memory address 0 4 bytes on 32-bit systems and 8 bytes on 64-bit systems

Table 7.0.1: Overview of the native data types in Gambas

7.0.1 Array data type

The native data types have an associated array data type whose name corresponds to the name of the native data type and follows the square brackets: {code_b_0}

The description of arrays can be found in chapter 20.12.

7.0.2 Data type functions

You can use the following functions to determine the data type. The argument passed to the data type functions is a string or a data type in SizeOf () or an expression in TypeOf (). The function value is either True or False or a memory value or a data type.

IsBoolean (string) Is true if string=“True” or string=“False” (comparison is not case-sensitive)
IsDate (string) Is true if string can be safely interpreted as date
IsFloat (string) Is true if string can be safely interpreted as float number
IsInteger (string) Is true if string can be safely interpreted as an integer
IsLong (string) Is true if string can be safely interpreted as a long integer number
IsNumber (string) Is true if string can be safely interpreted as a number
IsZero (string) Is true, if string is safe ZERO ist

Table Overview of the data type functions 1

SizeOf (data type) Specifies the memory used by a specific data type.
TypeOf (expression) Returns the data type of an expression.

Table Overview of Data Type Functions 2

The function value of SizeOf (data type) or TypeOf (expression) is one of the following constants:

Expression type Return value (numeric) Return value (symbolic)
Integer 4gb.Integer
Long 5gb.Long
Single 6gb.Single
Float 7gb.Float
Date 8gb.Date
String 9gb.String
Pointer 11gb.Pointer
Variant 12gb.Variant
Function 13gb.Function
Class 14gb.Class
Object 16 gb.Object

Table Overview of the function values of SizeOf (data type) and TypeOf (expression)


  • Note that TypeOf (ZERO) returns the numeric value 15 or gb. zero/.
  • The function Iszero (string) returns the function value True for the following arguments:
    • string is a ZERO constant
    • string is a ZERO object reference
    • The length of string is 0
    • string represents a zero date
    • string represents an uninitialized variable of type Variant
    • list point

7.0.3 Conversion of data types

Gambas provides functions for converting data types. For information on these functions, see chapter 9.7 Conversion Functions.

However, Gambas also automatically converts data types. For example,“2” is a string, but can also be interpreted as an integer 2 (integer) and can be used “on the fly” after a conversion, as the following examples show:

Public Sub OnTheFly_Click()
  Print "2" + 2 ' Integer-Number
  Print "Can '2' be interpreted as an integer number? ---> ";; IsInteger("2")
  Print "Type_1 = ";; TypeOf("2" + 2) ' 7 => Float
' String + Integer
' String -> Integer => 2 + 2 = 4
  Print "2" & 2 ' String
  Print "Type_2 = ";; TypeOf("2" & 2) ' 9 => String
' String & Integer
' Integer -> String => "2" & "2" = "22"
  Print 2.1 * ("2" & 2) ' Floating-point number
  Print "Type_3 =  ";; TypeOf(2.1 * ("2" & 2)) ' 7 => Float
' Float * (String & Integer)
' Integer -> String => "2" & "2" = "22"
' Float * String => 2.1 * "22"
' String -> Float => 2.1 * 22.0 = 46.2
End ' OnTheFly()

These are the expenses in the console:

Can '2' be interpreted as an integer number? --->  True
Type_1 =  7
Type_2 =  9
Type_3 =   7
The website uses a temporary session cookie. This technically necessary cookie is deleted when the browser is closed. You can find information on cookies in our privacy policy.
k7/start.txt · Last modified: 05.02.2022 (external edit)

Page Tools