Futurebasic/Language/Reference/begin record

Statement
✔ Appearance ✔  Standard ✔  Console

Syntax
begin record typeName recDefnBlock end record

Revised
July 19, 2000 (Release 3)

Description
Begins the definition of a "true" record type (as opposed to a pseudo-record type, which is defined using the  statements). The record type definition must end with an  statement.

A  block is non-executable, so you can't change its effect by putting it inside a conditional execution structure such as. However, you can conditionally include or exclude it from the program by putting it inside a  block.

The record type defined in the  block is global in scope, and can be used anywhere below where the block appears. is a name that identifies the record type. This name must be unique among all defined record types in your program. is a block of one or more  statements. These  statements have a syntax which is identical to that of an ordinary   statement. However, instead of declaring variables, these  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. You can also use the following "leading dot" syntax within the record definition block, to declare "empty" space; that is, some bytes within the record which are not identified by any field name: DIM .constant ...where  is an integer literal, or a symbolic constant name (without its leading underscore character). This declares the specified number of bytes as being "nameless."

You can also use the "semicolon" syntax after the definition of a field name, in order to specify how many bytes should be skipped between the beginning of this field and the beginning of the following field. You can use this either to insert "nameless" bytes within the record, or to make fields overlap in memory. See the  statement for more information about the semicolon syntax.

After a record type has been defined using, it can be used just like any other data type. This means:  You can declare variables as having type ; You can declare arrays as having type ; You can declare fields in other record types as having type .  Anywhere below the  statement, you can use the   statement, along with the   keyword, to declare a variable, array or field of type. For example, if you have defined a record type called, then you can do the following: dim myHouse as Address, yourHouse as Address dim relatives(15) as Address begin record EmployeeInfo dim 50 name$ dim 9 socSecNo$ dim 20 hobbies$[9] dim empAddress 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 and arrays of fields
When you use arrays of pseudo-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. For example, if we have a pseudo-record array called, then   refers to element #7 in the array. If this record type has a field called, then we represent the   of   as: game.score(7)    'pseudo-record Example: begin record StudentInfo dim 20 firstName$ dim 20 lastName$ dim 1 finalGrade$ end record dim myStudents(35) as StudentInfo 'This represents the final grade of myStudent #14: myStudents.finalGrade$(14)= &quot;B&quot;

Arrays inside of true records
True records have the ability to hold arrays inside of each record. This special embedded array is designated by using a bracket instead of a parenthesis for individual elements. The brackets are used for both dimensioning and accessing the sub-elements.

Example: begin record StudentInfo dim 20 firstName$ dim 20 lastName$ dim grades[100] end record dim myStudents(35) as StudentInfo 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.