Quick Reference - Tables

From QB64 Phoenix Edition Wiki
Jump to navigation Jump to search

QB64 Variable Types

         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.
(Return to Table of Contents)

OpenGL Types

   Table 2: Relations between the OpenGL variable types vs. C/C++ and QB64.
 ┌──────────────┬────────────────┬──────────────────────────────────────────┐
 │    OpenGLC/C++QB64                                 │
 ├──────────────┼────────────────┼──────────────────────────────────────────┤
 │ GLenum       │ unsigned int   │ _UNSIGNED LONG                           │
 ├──────────────┼────────────────┼──────────────────────────────────────────┤
 │ GLboolean    │ unsigned char  │ _UNSIGNED _BYTE                          │
 ├──────────────┼────────────────┼──────────────────────────────────────────┤
 │ GLbitfield   │ unsigned int   │ _UNSIGNED LONG                           │
 ├──────────────┼────────────────┼──────────────────────────────────────────┤
 │ GLbyte       │ signed char    │ _BYTE                                    │
 ├──────────────┼────────────────┼──────────────────────────────────────────┤
 │ GLshort      │ short          │ INTEGER                                  │
 ├──────────────┼────────────────┼──────────────────────────────────────────┤
 │ GLint        │ int            │ LONG                                     │
 ├──────────────┼────────────────┼──────────────────────────────────────────┤
 │ GLsizei      │ int            │ LONG                                     │
 ├──────────────┼────────────────┼──────────────────────────────────────────┤
 │ GLubyte      │ unsigned char  │ _UNSIGNED _BYTE                          │
 ├──────────────┼────────────────┼──────────────────────────────────────────┤
 │ GLushort     │ unsigned short │ _UNSIGNED INTEGER                        │
 ├──────────────┼────────────────┼──────────────────────────────────────────┤
 │ GLuint       │ unsigned int   │ _UNSIGNED LONG                           │
 ├──────────────┼────────────────┼──────────────────────────────────────────┤
 │ GLfloat      │ float          │ SINGLE                                   │
 ├──────────────┼────────────────┼──────────────────────────────────────────┤
 │ GLclampf     │ float          │ SINGLE                                   │
 ├──────────────┼────────────────┼──────────────────────────────────────────┤
 │ GLdouble     │ double         │ DOUBLE                                   │
 ├──────────────┼────────────────┼──────────────────────────────────────────┤
 │ GLclampd     │ double         │ DOUBLE                                   │
 ├──────────────┼────────────────┼──────────────────────────────────────────┤
 │ GLvoid   (1) │ void           │ _OFFSET(any fixed lenght string or _BYTE │
 │              │                │         array element)                   │
 └──────────────┴────────────────┴──────────────────────────────────────────┘
 Note: If a parameter has an asterisk (*) in front, then it's a pointer to
       the designated OpenGL variable type, rather than a value of that type.
       Those must be passed using the _OFFSET(...) notation.

 E.g.  GLuint *anyParam is actually the offset of a _UNSIGNED LONG (~&)
       variable or array, which must be passed as _OFFSET(anyVar~&) or
       _OFFSET(anyArr~&()) respectively.

  (1)  This type is regularly only used for pointers (with asterisk (*)) to
       any byte sized memory data, hence _BYTE or fixed length strings.
(Return to Table of Contents)

Relational Operations

         Table 3: The relational operations for condition checking.

 In this table, A and B are the Expressions to compare. Both must represent
 the same general type, i.e. they must result into either numerical values
 or STRING values. If a test succeeds, then true (-1) is returned, false (0)
     if it fails, which both can be used in further Boolean evaluations.
 ┌─────────────────────────────────────────────────────────────────────────┐
 │                          Relational Operations                          │
 ├────────────┬───────────────────────────────────────────┬────────────────┤
 │ OperationDescriptionExample usage  │
 ├────────────┼───────────────────────────────────────────┼────────────────┤
 │   A = B    │ Tests if A is equal to B.                 │ IF A = B THEN  │
 ├────────────┼───────────────────────────────────────────┼────────────────┤
 │   A <> B   │ Tests if A is not equal to B.             │ IF A <> B THEN │
 ├────────────┼───────────────────────────────────────────┼────────────────┤
 │   A < B    │ Tests if A is less than B.                │ IF A < B THEN  │
 ├────────────┼───────────────────────────────────────────┼────────────────┤
 │   A > B    │ Tests if A is greater than B.             │ IF A > B THEN  │
 ├────────────┼───────────────────────────────────────────┼────────────────┤
 │   A <= B   │ Tests if A is less than or equal to B.    │ IF A <= B THEN │
 ├────────────┼───────────────────────────────────────────┼────────────────┤
 │   A >= B   │ Tests if A is greater than or equal to B. │ IF A >= B THEN │
 └────────────┴───────────────────────────────────────────┴────────────────┘
   The operations should be very obvious for numerical values. For strings
   be aware that all checks are done case sensitive (i.e. "Foo" <> "foo").
   The equal/not equal check is pretty much straight forward, but for the
   less/greater checks the ASCII value of the first different character is
                          used for decision making:

   E.g. "abc" is less than "abd", because in the first difference (the 3rd
        character) the "c" has a lower ASCII value than the "d".

   This behavior may give you some subtle results, if you are not aware of
                   the ASCII values and the written case:

   E.g. "abc" is greater than "abD", because the small letters have higher
        ASCII values than the capital letters, hence "c" > "D". You may use
        LCASE$ or UCASE$ to make sure both strings have the same case.
(Return to Table of Contents)

Logical Operations

               Table 4: The logical operations and its results.

       In this table, A and B are the Expressions to invert or combine.
              Both may be results of former Boolean evaluations.
  ┌────────────────────────────────────────────────────────────────────────┐
  │                           Logical Operations                           │
  ├───────┬───────┬───────┬─────────┬────────┬─────────┬─────────┬─────────┤
  │   ABNOT BA AND BA OR BA XOR BA EQV BA IMP B │
  ├───────┼───────┼───────┼─────────┼────────┼─────────┼─────────┼─────────┤
  │ truetrue  │ false │  true   │ true   │  false  │  true   │  true   │
  ├───────┼───────┼───────┼─────────┼────────┼─────────┼─────────┼─────────┤
  │ truefalse │ true  │  false  │ true   │  true   │  false  │  false  │
  ├───────┼───────┼───────┼─────────┼────────┼─────────┼─────────┼─────────┤
  │ falsetrue  │ false │  false  │ true   │  true   │  false  │  true   │
  ├───────┼───────┼───────┼─────────┼────────┼─────────┼─────────┼─────────┤
  │ falsefalse │ true  │  false  │ false  │  false  │  true   │  true   │
  └───────┴───────┴───────┴─────────┴────────┴─────────┴─────────┴─────────┘
   Note: In most BASIC languages incl. QB64 these are bitwise operations,
         hence the logic is performed for each corresponding bit in both
         operators, where true or false indicates whether a bit is set or
         not set. The outcome of each bit is then placed into the respective
         position to build the bit pattern of the final result value.

   As all Relational Operations return negative one (-1, all bits set) for
    true and zero (0, no bits set) for false, this allows us to use these
    bitwise logical operations to invert or combine any relational checks,
    as the outcome is the same for each bit and so always results into a
            true (-1) or false (0) again for further evaluations.
(Return to Table of Contents)

Formatted Print Symbols

   Table 5: The formatting symbols used by the [L]PRINT USING[#] commands.
  ┌───────┬────────────────────────────────────────────────────────────────┐
  │   &   │ Prints an entire string value. STRING length should be limited │
  │       │ as template width will vary.                                   │
  ├───────┼────────────────────────────────────────────────────────────────┤
  │ \   \ │ Denotes the start and end point of a fixed string area with    │
  │       │ spaces between(LEN = spaces + 2).                              │
  ├───────┼────────────────────────────────────────────────────────────────┤
  │   !   │ Prints only the leading character of a string value.           │
  ├───────┼────────────────────────────────────────────────────────────────┤
  │   #   │ Denotes a numerical digit. An appropriate number of digits     │
  │       │ should be used for values received.                            │
  ├───────┼────────────────────────────────────────────────────────────────┤
  │ ^^^^  │ After # digits prints numerical value in exponential E+xx      │
  │       │ format. Use ^^^^^ for E+xxx values. (1)                        │
  ├───────┼────────────────────────────────────────────────────────────────┤
  │   .   │ Period sets a number's decimal point position. Digits following│
  │       │ determine rounded value accuracy.                              │
  ├───────┼────────────────────────────────────────────────────────────────┤
  │  ,.Comma to left of decimal point, prints a comma every 3 used #  │
  │       │ digit places left of the decimal point.                        │
  ├───────┼────────────────────────────────────────────────────────────────┤
  │   +   │ Plus sign denotes the position of the number's sign. + or -    │
  │       │ will be displayed.                                             │
  ├───────┼────────────────────────────────────────────────────────────────┤
  │   -   │ Minus sign (dash) placed after the number, displays only a     │
  │       │ negative value's sign.                                         │
  ├───────┼────────────────────────────────────────────────────────────────┤
  │  $$   │ Prints a dollar sign immediately before the highest non-zero # │
  │       │ digit position of the numerical value.                         │
  ├───────┼────────────────────────────────────────────────────────────────┤
  │  **   │ Prints an asterisk in any leading empty spaces of a numerical  │
  │       │ value. Adds 2 extra digit positions.                           │
  ├───────┼────────────────────────────────────────────────────────────────┤
  │  **$  │ Combines ** and $$. Negative values will display minus sign to │
  │       │ left of $.                                                     │
  ├───────┼────────────────────────────────────────────────────────────────┤
  │   _Underscore preceding a format symbol prints those symbols as   │
  │       │ literal string characters.                                     │
  └───────┴────────────────────────────────────────────────────────────────┘
     Note: Any string character not listed above will be printed as a
           literal text character.

       (1) Any # decimal point position may be specified. The exponent is
           adjusted with significant digits left-justified.
(Return to Table of Contents)



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