Jump to content

Programming Gambas from Zip/DataTypes

From Wikibooks, open books for an open world

Data Types and Conversions

[edit | edit source]

Data Types

[edit | edit source]

One byte is the amount of memory required to store a single character such as the letter “A” or the digit “1”. It is eight bits (1’s or 0’s, like little switches that are on or off, up or down). 8 bits = 1 byte. 4 bits = 1 nibble, but that one is not used much.

http://Gambaswiki.org/wiki/lang/type

Description and Limits Default value Size in memory
Boolean True or false FALSE 1 byte
Byte 0 to 255 0 1 byte
Short -32,768 to +32,767 0 2 bytes
Integer -2,147,483,648 to +2,147,483,647 0 4 bytes
Long -9,223,372,036,854,775,808 to 9,223,372,036,854,775,807 0 8 bytes
Single Single precision 0.0 4 bytes
Float Floating point or double precision 0.0 8 bytes
Date Date and time, each stored in an integer. NULL 8 bytes
String A variable length string of characters. NULL 4 bytes on 32 bits systems, 8 bytes on 64 bits systems
Variant Any datatype. NULL 12 bytes on 32 bits systems, 16 bytes on 64 bits systems
Object Anonymous reference to any object. NULL 4 bytes on 32 bits systems, 8 bytes on 64 bits systems.
Pointer A memory address. 0 4 bytes on 32 bits systems, 8 bytes on 64 bits systems

Conversions

[edit | edit source]

Some conversions are omitted. Many of these conversions are done automatically as required. For example, these are fine without explicitly having to write the functions:

label1.text = 54.65

Dim d As Date = "09/06/1972 01:45:12"

Dim d As Date = 2484515 gives d the date 05/16/2002
CBool to a Boolean An expression is false if it is
  • A false boolean
  • A zero number
  • A zero length string
  • A null date
  • A null object

CBool(0) is false

CBool(1) is true

CBool("Gambas") is true

CBool("") is false

CBool(Null) is false

0 → False; Anything else → True

e.g. 6 is True; -4 is True; 3-(1+2) is False.

CDate to a Date CDate("09/06/1972 01:45:12")

CDate(2484515)

CFloat or CFlt to a Float CFloat("+3.1416")

Cfloat("1.0E+3") is 1000

CInt or CInteger to an Integer CInt("17") is the number 17

CInt(True) is -1

CInt(Now) is 2490779

CInt(3.2) is 3

CInt(3.9) is 3

CInt(6) is 6

CInt(-7.2) is -7

CInt(-7.9) is -7

TRUE → -1 FALSE → 0

CStr or CString to a String CStr(-1972) is -1972

CStr(Now) is 05/16/2002 15:08:31

CStr(Pi) is 3.14159265359

Str a number or a date into a string The opposite of Val()

Use Format() to have control of what form the number or date takes.

Val a string into a number or a date Conversion follows these steps until if finds something it can convert:

Look for a date

Look for a long

Look for an integer

Look for a true or false

If none, return NULL.

IsNull(Val("Gambas")) is True


Programming Gambas from Zip
 ← Operators DataTypes Formatting →