free web page software

DATA TYPES

BOOLEAN DATA TYPE


The BOOLEAN data type is a data types that can hold one of two values:- TRUE or FALSE. BOOLEAN variables and arrays are defined using the DIM statement.


DIM X AS BOOLEAN

DIM X(5) AS BOOLEAN

DIM X(5,…) AS BOOLEAN

BOOLEAN Data Type - Example


SUB MAIN

    DIM X AS BOOLEAN

    X=FALSE

    PRINT "X=" + STR$(X)

    X=TRUE

    PRINT "X=" + STR$(X)

END SUB

BYTE DATA TYPE (8 Bit Signed Integer)

The BYTE data type is a signed integer type that can hold values from -128 to +127. BYTE variables and arrays are defined using the DIM statement. The BYTE(…) function is used to convert any other numeric value into a BYTE data type.


DIM X AS BYTE

DIM X(5) AS BYTE

DIM X(5,…) AS BYTE

BYTE Data Type - Example

SUB MAIN

    DIM X AS BYTE

    X=BYTE(0x80)

    PRINT "X=" + STR$(X)

    X= BYTE(127)

    PRINT "X=" + STR$(X)

END SUB

COMPLEX DATA TYPE

The COMPLEX data type holds a number that consists of a real number together with an imaginary number which hare both stored as double precision. COMPLEX variables and arrays are defined using the DIM statement. The COMPLEX(…) function is used to convert any other numeric value into a DOUBLE data type. The REAL(…) function returns the real part of a complex number as a double precision floating point value. The IMAGINARY(…) function returns the imaginary part of a complex number as a double precision floating point value.


DIM X AS COMPLEX

DIM X(5) AS COMPLEX

DIM X(5,…) AS COMPLEX

COMPLEX Data Type - Example

SUB MAIN

    DIM X1, X2, X3 AS COMPLEX

    X1 = COMPLEX(25.0) // Real=25, Imaginary defaults to 0

    X2 = COMPLEX(3.2, -2.2) // Real=3.2, Imaginary=-2.2

    X3 = X1 * X2

    PRINT X1, X2, X3

    PRINT REAL(X3)

    PRINT IMAGINARY(X3)

END SUB

DOUBLE DATA TYPE (64 Bit Double Precision Floating Point)

The DOUBLE data type is a double precision (15 significant digits) floating point number that can hold values from ±4.9E-324 to ±1.7976931348623157E+308. DOUBLE variables and arrays are defined using the DIM statement. The DOUBLE(…) function is used to convert any other numeric value into a DOUBLE data type.


DIM X AS DOUBLE

DIM X(5) AS DOUBLE

DIM X(5,…) AS DOUBLE

DOUBLE Data Type - Example

SUB MAIN

    DIM X AS DOUBLE

    X=1.234E+2

    PRINT "X=" + STR$(X)

    X=-1234.56E-2

    PRINT "X=" + STR$(X)

    X=321.1234567890123

    PRINT "X=" + STR$(X)

    X=PI

    PRINT "X=" + STR$(X)

END SUB

FLOAT DATA TYPE (32 Bit Single Precision Floating Point)

The FLOAT data type is a single precision (7 significant digits) floating point number that can hold values from ±1.4E-45 to ±3.4028235E+38. FLOAT variables and arrays are defined using the DIM statement. The FLOAT(…) function is used to convert any other numeric value into a FLOAT data type.


DIM X AS FLOAT

DIM X(5) AS FLOAT

DIM X(5,…) AS FLOAT

FLOAT Data Type - Example

SUB MAIN

    DIM X AS FLOAT

    X=321.1234f

    PRINT "X=" + STR$(X)

    X=1.234E+2f

    PRINT "X=" + STR$(X)

    X=-1234.56E-2f

    PRINT "X=" + STR$(X)

END SUB

INTEGER DATA TYPE (32 Bit Signed Integer)

The INTEGER data type is a signed integer type that can hold values from -2147483648 to +2147483647. INTEGER variables and arrays are defined using the DIM statement. The INTEGER(…) function is used to convert any other numeric value into an INTEGER data type.


DIM X AS INTEGER

DIM X(5) AS INTEGER

DIM X(5,…) AS INTEGER

INTEGER Data Type - Example

SUB MAIN

    DIM X AS INTEGER

    X=1234

    PRINT X

    X=0x80000000

    PRINT X

    X=0x7fffffff

    PRINT X

END SUB

LONG DATA TYPE (64 Bit Signed Integer)

The LONG data type is a signed integer type that can hold values from -9223372036854775808 to +9223372036854775807. LONG variables and arrays are defined using the DIM statement. The LONG(…) function is used to convert any other numeric value into a LONG data type.


DIM X AS LONG

DIM X(5) AS LONG

DIM X(5,…) AS LONG

LONG Data Type - Example

SUB MAIN

    DIM X AS LONG

    X=123L

    PRINT X

    X=0x8000000000000000L

    PRINT X

    X=0x7fffffffffffffffL

    PRINT X

END SUB

SHORT DATA TYPE (16 Bit Signed Integer)

The SHORT data type is a signed integer type that can hold values from -32768 to +32767. SHORT variables and arrays are defined using the DIM statement. The SHORT(…) function is used to convert any other numeric value into a SHORT data type.


DIM X AS SHORT

DIM X(5) AS SHORT

DIM X(5,…) AS SHORT

SHORT Data Type - Example

SUB MAIN

    DIM X AS SHORT

    X=SHORT(123)

    PRINT X

    X=SHORT(0x8000)

    PRINT X

    X=SHORT(0x7fff)

    PRINT X

END SUB

STRING DATA TYPE

The STRING data type is used to declare variables that contain text strings. STRING variables and arrays are defined using the DIM statement. The STRING(…) function is used to convert any other value into a STRING data type.


DIM X AS STRING

DIM X(5) AS STRING

DIM X(5,…) AS STRING

STRING Data Type - Example

SUB MAIN

    DIM X AS STRING

    X="Backslash character=\\"

    PRINT "X: " + X

    X="Quote Character=\""

    PRINT "X: " + X

    X="First line\nSecond line"

    PRINT "X: " + X

    X=STRING(123)

    PRINT "X=" + X

END SUB

VARIANT DATA TYPE

The VARIANT data type is a special data type that can hold different types of data at different times. In most cases you should use one of the other types but it can be useful to make functions that can process different types of data (see last example). VARIANT variables and arrays are defined using the DIM statement. The VARIANT(…) function is used to convert any other values into a VARIANT data type.


DIM X AS VARIANT

DIM X(5) AS VARIANT

DIM X(5,…) AS VARIANT

VARIANT Data Type - Example 1


SUB MAIN

    DIM X AS VARIANT

    X=VARIANT(3.142)

    PRINT X

    X=VARIANT("String Value")

    PRINT X

END SUB

VARIANT Data Type - Example 2


FUNCTION DBL(X AS VARIANT) AS VARIANT

    DBL = X + X

END FUNCTION


SUB MAIN

    DIM V AS VARIANT

    V=VARIANT(5)

    PRINT DBL(V)

    V=VARIANT(5.5)

    PRINT DBL(V)

    V=VARIANT(COMPLEX(2.2,1.1))

    PRINT DBL(V)

    V=VARIANT("Test")

    PRINT DBL(V)

END SUB