FutureBasic Logo

<<    Index    >> FutureBasic

begin record   statement

begin record TypeName
end record

Begins the definition of a "record" type. The record type definition must end with an end record statement.
A begin record...end record block is non-executable, so you can't change its effect by putting it inside a conditional execution structure such as if...end if. However, you can conditionally include or exclude it from the program by putting it inside a #if block.
The record type defined in the begin record...end record block is global in scope, and can be used anywhere below where the block appears.
TypeName is a name that identifies the record type. This name must be unique among all defined record types in your program.
recDefnBlock is a block of one or more dim statements. These dim statements have a syntax which is identical to that of an ordinary dim statement. However, instead of declaring variables, these dim statements declare the names and types of the fields in this type of record. The field names do not need to be unique to this type of record (that is, a different record type could use some of the same field names as this record type). A field can be of any data type, including a previously-defined record type. A field may also be an array of elements of any type.

After a record type has been defined using begin record...end record, it can be used just like any other data type. This means that you can declare:

Anywhere below the end record statement, you can use the dim statement, along with the as keyword, to declare a variable, array or field of type TypeName. For example, if you have defined a record type called Address, then you can do the following:
dim myHouse as Address, yourHouse as Address
dim relatives(15) as Address
begin record EmployeeInfo
  dim as Str63 name
  dim 9 socSecNo$
  dim 20 hobbies$[9]
  dim empAdress as Address
end record
After you have declared a variable of a given record type, then you can use the "embedded dot" syntax to refer to individual fields within the record. Using the above example:
dim mySecretary as EmployeeInfo
mySecretary.socSecNo$ = "456-78-9999"

Arrays of records
When you use arrays of records, you always write the array subscript at the end of the expression, whether the expression indicates an entire record or one of its fields.
begin record StudentInfo
  dim as Str63 firstName, lastName
  dim 1 finalGrade$
end record
dim myStudents(35) as StudentInfo
// This represents the final grade of myStudent #14:
myStudents.finalGrade$(14)= "B"

Arrays inside records
An array field is declared in a similar fashion to an ordinary array declaration, except that square brackets are used instead of parentheses. Brackets are used for both dimensioning and accessing the array's elements.
begin record StudentInfo
  dim as Str63 firstName, lastName
  dim grades[100] // note square brackets
end record
dim as StudentInfo myStudents(35)
myStudents.grades[1](5) = 96
In the final line of this example, the grade element number 1 of student number 5 is set to 96.

See also
dim; begin union; sizeof