55
TIDE and Tibbo BASIC User Manual
©2000-2008 Tibbo Technology Inc.
Basic supports up to eight nesting levels (as in "array within a structure within a
structure within and array" -- each structure or array is one level and up to 8
levels are possible). Here is a complex example:
type
foo_struct
'structure with two members, and both are arrays
x(10)
as
byte
s(10)
as
string
(4)
end
type
type
bar_struct
'structure with two members, one if which is another
structure
foo
as
foo_struct
'so, this member is a structure
w
as
word
end
type
dim
bar(20)
as
bar_struct
'we define an array of type 'bar_struct'
bar(1).foo.s(2)="test"
'oh-ho! we address element 2 of member s of member
foo of element 1 of bar!
Structures introduce slight overhead
Each structure occupies more space than the sum total of space needed by all of
its members. This is because each structure also includes housekeeping data that,
for instance, defines how many members are there, what type they have, etc.
4.2.4.7
Enumeration Types
At times, it may be useful for a programmer to define his own enumeration data
types; for example, when working with the days of the week, it may be useful to
refer to them by name in code, rather than by number:
dim
i
as
integer
i =
2
' i is an integer, and can only be assigned a numerical value. you
would have to remember that 2 is Monday.
dim
d
as
dayofweek
d = monday
' now d is a user-defined type, dayofweek, and can be assigned
a value using the symbol Monday.
Enumeration definitions are made like this:
enum
dayofweek
sunday = 1,
' if 1 is not specified, the default value associated
with the first constant is 0.
monday,
' by default, increments the previous value by 1. can
also be explicitly specified.
tuesday,
wednsday,
thursday,
friday,
saturday,
holiday = 99,
' as described above, values can be explicitly associated
with any constant in the list.
holiday2
'this will have the value of 100
end
enum
An enumeration type would then be used within the code as shown above (d =