Variable Types

From QB64 Phoenix Edition Wiki
Jump to navigation Jump to search

QB64 uses more variable types than QBasic ever did. The variable type determines the size of values that numerical variables can hold.

         Table 1: The variable types supported by the QB64 language.
┌───────────────────────────────────────────────────────────────────────────┐
│                              Numerical types                              │
├──────────────────────┬───────────┬────────────────────────────┬───────────┤
│      Type NameTypeMinimum valueSize in  │
│                      │  suffixMaximum valueBytes   │
├──────────────────────┼───────────┼────────────────────────────┼───────────┤
│         _BIT         │     `     │                         -1 │    1/8    │
│                      │           │                          0 │           │
├──────────────────────┼───────────┼────────────────────────────┼───────────┤
│       _BIT * n       │    `n     │                       -128 │    n/8    │
│                      │           │                        127 │           │
├──────────────────────┼───────────┼────────────────────────────┼───────────┤
│    _UNSIGNED _BIT    │    ~`     │                          0 │    1/8    │
│                      │           │                          1 │           │
├──────────────────────┼───────────┼────────────────────────────┼───────────┤
│        _BYTE         │    %%     │                       -128 │     1     │
│                      │           │                        127 │           │
├──────────────────────┼───────────┼────────────────────────────┼───────────┤
│   _UNSIGNED _BYTE    │    ~%%    │                          0 │     1     │
│                      │           │                        255 │           │
├──────────────────────┼───────────┼────────────────────────────┼───────────┤
│       INTEGER        │     %     │                    -32,768 │     2     │
│                      │           │                     32,767 │           │
├──────────────────────┼───────────┼────────────────────────────┼───────────┤
│  _UNSIGNED INTEGER   │    ~%     │                          0 │     2     │
│                      │           │                     65,535 │           │
├──────────────────────┼───────────┼────────────────────────────┼───────────┤
│         LONG         │     &     │             -2,147,483,648 │     4     │
│                      │           │              2,147,483,647 │           │
├──────────────────────┼───────────┼────────────────────────────┼───────────┤
│    _UNSIGNED LONG    │    ~&     │                          0 │     4     │
│                      │           │              4,294,967,295 │           │
├──────────────────────┼───────────┼────────────────────────────┼───────────┤
│      _INTEGER64      │    &&     │ -9,223,372,036,854,775,808 │     8     │
│                      │           │  9,223,372,036,854,775,807 │           │
├──────────────────────┼───────────┼────────────────────────────┼───────────┤
│ _UNSIGNED _INTEGER64 │    ~&&    │                          0 │     8     │
│                      │           │ 18,446,744,073,709,551,615 │           │
├──────────────────────┼───────────┼────────────────────────────┼───────────┤
│        SINGLE        │     !     │              -2.802597E-45 │     4     │
│                      │ (or none) │              +3.402823E+38 │           │
├──────────────────────┼───────────┼────────────────────────────┼───────────┤
│        DOUBLE        │     #     │    -4.490656458412465E-324 │     8     │
│                      │           │    +1.797693134862310E+308 │           │
├──────────────────────┼───────────┼────────────────────────────┼───────────┤
│        _FLOAT        │    ##     │                -1.18E-4932 │    32     │
│                      │           │                +1.18E+4932 │ (10 used) │
├──────────────────────┼───────────┼────────────────────────────┼───────────┤
│       _OFFSET        │    %&     │ -9,223,372,036,854,775,808 │  use LEN  │
│                      │           │  9,223,372,036,854,775,807 │           │
├──────────────────────┼───────────┼────────────────────────────┼───────────┤
│  _UNSIGNED _OFFSET   │    ~%&    │                          0 │  use LEN  │
│                      │           │ 18,446,744,073,709,551,615 │           │
├──────────────────────┼───────────┼────────────────────────────┴───────────┤
│         _MEM         │   none    │ An internal TYPE like memory variable. │
└──────────────────────┴───────────┴────────────────────────────────────────┘
  For the floating-point numeric types SINGLE (default when not assigned),
 DOUBLE and _FLOAT, the minimum values represent the smallest values closest
  to zero, while the maximum values represent the largest values closest to
    pos./neg. infinity. _OFFSET dot values are used as a part of the _MEM
       variable type in QB64 to return or set the position in memory.

┌───────────────────────────────────────────────────────────────────────────┐
│                                Text types                                 │
├──────────────────────┬───────────┬────────────────────────────┬───────────┤
│      Type NameTypeMinimum valueSize in  │
│                      │  suffixMaximum valueBytes   │
├──────────────────────┼───────────┼────────────────────────────┼───────────┤
│        STRING        │     $     │                          0 │  use LEN  │
│                      │           │              2,147,483,647 │           │
├──────────────────────┼───────────┼────────────────────────────┼───────────┤
│      STRING * n      │    $n     │                          1 │     n     │
│                      │           │              2,147,483,647 │           │
└──────────────────────┴───────────┴────────────────────────────┴───────────┘
  While a regular variable length STRING may have a minimum length of zero
   (empty string), the fixed length string type STRING * n, where n is an
 integer length value, must have a minimum length of at least one character.

If no suffix is used and no DEFxxx or _DEFINE command has been used and the variable hasn't been DIMmed the default variable type is SINGLE. _MEM and _OFFSET variable types cannot be cast to other variable types!


All types dealing with number values are signed as a default. The symbol to define unsigned variables is ~ and is used just before the type suffix (~` is _UNSIGNED _BIT, ~%% is _UNSIGNED _BYTE, etc.).


SINGLE, DOUBLE and _FLOAT floating decimal point values cannot be _UNSIGNED!


Defining variable types:

DIM variable AS type
_DEFINE range1-range2 AS value_type
DEFINT range1-range2
DEFLNG range1-range2
DEFSNG range1-range2
DEFDBL range1-range2

Where range1 and range2 are the range of first letters to be defined as the default type when the variable is having no suffix and are not otherwise defined, the starting letter of the variable then defines the type as specified by the DEFxxx and _DEFINE statements. The QB64 types can only be defaulted using _DEFINE.

type can be any of the types listed at the top and can also be preceeded with _UNSIGNED for the unsigned version of the type.

variable is the name of the variable to be defined in the DIM statement.


More information:

More information on this page: Data types



Navigation:
Main Page with Articles and Tutorials
Keyword Reference - Alphabetical
Keyword Reference - By usage