[next] [previous] [contents]

  9.1.3 Accessing RECORD Components
  To access a particular elementary component within a
  RECORD that contains other groups, you use the name of
  the declared RECORD instance, the group name (or group
  names, if groups are nested), and the elementary component
  name, each separated by double colons (::).

  In the following example, the PRINT statement displays the
  Rig
component in the Specifications group in the variable
  named My_yacht . The RECORD instance name qualifies
  the group name and the group name qualifies the elemen-
  tary RECORD component. The elementary component
  name, qualified by all intermediate group names and by the
  RECORD instance name, is called a fully qualified com-
  ponent
. The full qualification of a component is called a
  component path name
.
  DECLARE Yacht My_yacht
      .
      .
      .

  PRINT My_yacht::Specifications::Rig

  Because it is cumbersome to specify the entire component
  path name, BASIC allows elliptical references to RECORD
  components. GROUP names are optional in the component
  path name unless:

  .
        A RECORD contains more than one component with the
        same name
  .
        The GROUP is an array

  The rules for using elliptical references are as follows:

  .
        You must always specify the RECORD instance, that is,
        the name of the declared variable.
  .
        You must always specify any dimensioned group.
  .
        You may omit any other intermediate component names.
  .
        You must specify the final component name.

  The following example shows that using the complete com-
  ponent path name is valid but not required. The assignment
  statement uses the fully qualified component name; the
  PRINT statement uses an elliptical reference to the same
  component, omitting Extended_family and Nuclear_family
  GROUP names. Note that the Children GROUP name is
  required because the GROUP is an array; the elliptical ref-
  erence to this component must include the desired array
  element, in this case the second element of the Children
  array.
  
EXAMPLE: Click to display example.

  Output
  Johnny
  
EXAMPLE: Click to display example.

  The minimal reference to the string Group_1_string in
  RECORD instance Array_of_test is as follows:
  Array_of_test(i)::Group_1_string

  In this case, i is the subscript for array Array_of_test .
  Because the RECORD instance is itself an array, the ref-
  erence must include a specific array element.

  Because Single_test is not an array, the minimal reference to
  string Group_1_string in RECORD instance Single_test is as
  follows:
  Single_test::Group_1_string

  The minimal reference for the REAL variable My_number in
  GROUP Group_1 in RECORD instance Array_of_test is as
  follows:
  Array_of_test(i)::Group_1::My_number

  Here, i is the subscript for array Array_of_test . The mini-
  mal reference to the REAL variable My_number in RECORD
  instance Single_test is as follows:
  Single_test::Group_1::My_number

  Because there is a variable named My_number in groups
  Group_1
and Group_2 , you must specify either Group_1::My_
  number
or Group_2(i)::My_number . In this case, extra com-
  ponent names are required to resolve an otherwise ambiguous
  reference.

  The minimal reference to the DECIMAL variable Group_2_
  decimal
in RECORD instances Array_of_test and Single_test
  are the fully qualified references. In the following examples, i
  is the subscript for array Array_of_test and j is an index into
  the group array Group_2 . Even though Group_2_decimal is
  a unique component name within RECORD instance Single_
  test
, the element of array Group_2 must be specified. In this
  case, the extra components must be specified because each
  element of GROUP Group_2 contains a component named
  Group_2_decimal
.
  Array_of_test(i)::Group_2(j)::Group_2_decimal
  Single_test::Group_2(j)::Group_2_decimal

  You can assign all the values from one RECORD instance to
  another RECORD instance, as long as the RECORD instances
  are identical except for names.

  In the following example, RECORD instances First_test1 ,
  Second_test1
, and the individual elements of array Array_
  of_test1
have the same form: an array of four groups, each
  of which contains a 10-byte string variable, followed by a
  REAL variable, followed by an INTEGER variable. Any of
  these RECORD instances can be assigned to one another.
  
EXAMPLE: Click to display example.

  Further, you can assign values from single RECORD in-
  stances to groups contained in other instances.

  In the following example, Array_of_test1 and First_test1 do
  not have the same form because Array_of_test1 is an ar-
  ray of RECORD Test1 and First_test1 is a single instance of
  RECORD Test1 . Therefore, First_test1 and Array_of_test1
  cannot be assigned to one another.
  ! A single instance is assigned to one group
  Array_of_test1(3)::Group_1(2) = First_test1
  ! An array element is assigned a value from
  ! a group contained in another array instance
  Array_of_test3(5) = Array_of_test1(3)::Group_1(3)

  The examples shown in this chapter explain the mechanics of
  using data structures. See
Chapter 13 for more information
  about using data structures as parameters. See Chapter 14
  for more information about using data structures for file
  input and output.