Q(uick)BASIC Data Types: User-Defined
Quick View
User-Defined Data Types
BASIC lets you define new data types using the TYPE statement
Worth knowing
Useful and cross-version information about the programming environments of QBasic and QuickBasic.
Description/Parameter(s)
A user-defined type is an aggregate type made up of elementary BASIC types. For example, the following TYPE statement defines a type, SymTabEntry:
TYPE SymTabEntry
Identifier AS STRING * 40
LineNumber AS LONG
Value AS LONG
END TYPE
The new type contains a fixed-length string and two long integers. A variable of a user-defined type occupies only as much storage as the sum of its components. A SymTabEntry takes up 48 bytes: 40 bytes for the fixed- length string and 4 bytes each for the two long integers.
You may use any of the basic data types (except variable-length strings) in a user-defined type: short and long integers, single- and double-precision floating-point values, and fixed-length strings.
Note: | User-defined types cannot include arrays or variable-length strings. |
Description/Parameter(s)
A user-defined type, also called a record, is an aggregate type made up of elementary BASIC types. Elements of a user-defined type can be different data types. For example, the following TYPE statement defines a type, InventoryItem:
TYPE InventoryItem
Quantity AS LONG
OrderPoint AS LONG
Cost AS CURRENCY
VendorCodes(1 TO 10) AS INTEGER
Description AS STRING * 25
Number AS STRING * 10
END TYPE
The new type InventoryItem contains two long integers, one currency item, a static array of integers, and two fixed-length strings. A variable of a user-defined type occupies only as much storage as the sum of its components. InventoryItem takes up 71 bytes: 4 bytes each for the two long integers (8 bytes total), 8 bytes for the currency item, 20 bytes for the static array, and 35 bytes for the fixed-length strings.
You may use any of the BASIC data types (except variable-length strings) in a user-defined type: short and long integers, single- and double-precision floating-point values, currency, fixed-length strings, static arrays, and other user-defined types. User-defined types cannot include variable-length strings or dynamic arrays.
Data Types in ISAM Files
- Some special restrictions apply to BASIC ISAM files. When you create an ISAM table, you create a user-defined data type by including an appropriate TYPE...END TYPE statement in the declarations part of your program.