Futurebasic/Language/Reference/begin record

Begin Record edit

Statement edit

✔ Appearance ✔ Standard ✔ Console

Syntax edit

begin record typeName
end record

Revised edit

July 19, 2000 (Release 3)

Description edit

Begins the definition of a "true" record type (as opposed to a pseudo-record type, which is defined using the dim record...dim end record statements). 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 long if/end if. However, you can conditionally include or exclude it from the program by putting it inside a compile long 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.

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 constant 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 dim statement for more information about the semicolon syntax.

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

  • You can declare variables as having type typeName;
  • You can declare arrays as having type typeName;
  • You can declare fields in other record types as having type typeName.

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 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 edit

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 game, then game(7) refers to element #7 in the array. If this record type has a field called score, then we represent the score of game(7) as:

game.score(7)     'pseudo-record


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)= "B"

Arrays inside of true records edit

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.


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.

Notes edit

No special notes.

See Also edit

dim record...dim end record; dim; begin union; sizeof; offsetof

Language Reference