Share via


GATHER Command

Replaces the data in the current record of the currently selected table with data from an array, a set of variables, or an object.

GATHER FROM ArrayName | MEMVAR | NAME ObjectName
   [FIELDS FieldList | FIELDS LIKE Skeleton | FIELDS EXCEPT Skeleton]
   [MEMO]

Parameters

  • FROM ArrayName
    Specifies the array whose data replaces the data in the current record. The contents of the elements of the array, starting with the first element, replace the contents of the corresponding fields of the record. The contents of the first array element replace the first field of the record; the contents of the second array element replace the second field, and so on.

    If the array has fewer elements than the table has fields, the additional fields are ignored. If the array has more elements than the table has fields, the additional array elements are ignored.

  • MEMVAR
    Specifies the variables or array from which data is copied to the current record. Data is transferred from the variable to the field that has the same name as the variable. The contents of a field are not replaced if a variable doesn't exist with the same name as the field.

    Tip   You can create variables with the same names as fields by including MEMVAR or BLANK in SCATTER.

  • NAME ObjectName
    Specifies an object whose properties have the same names as fields in the table. The contents of each field are replaced by the value of the property with the same names as the fields. The contents of a field are not replaced if a property doesn't exist with the same name as the field.

  • FIELDS FieldList
    Specifies the fields whose contents are replaced by the contents of the array elements or variables. Only the field specified with FieldList has its contents replaced.

  • FIELDS LIKE Skeleton | FIELDS EXCEPT Skeleton
    You can selectively replace fields with the contents of array elements or variables by including the LIKE or EXCEPT clause or both. If you include LIKE Skeleton, Visual FoxPro replaces the fields that match Skeleton. If you include EXCEPT Skeleton, Visual FoxPro replaces all fields except those that match Skeleton.

    Skeleton supports wildcards (* and ?). For example, to replace all fields that begin with the letters A and P, use:

    GATHER FROM gamyarray FIELDS LIKE A*,P*
    
  • MEMO
    Specifies that the contents of memo fields are replaced with the contents or array elements or variables. If you omit MEMO, memo fields are skipped when GATHER replaces the contents of fields with the contents of an array or variable. General and picture fields are always ignored in GATHER, even if you include the MEMO keyword.

Example

This example uses GATHER to copy data to a new record in a table. After the table Test is created, SCATTER is used to create a set of variables based on the fields in the table. Each field is then assigned a value and a new blank record is added to the table.

CREATE TABLE Test FREE ;
   (Object C(10), Color C(16), SqFt n(6,2))
SCATTER MEMVAR BLANK
m.Object="Box"
m.Color="Red"
m.SqFt=12.5
APPEND BLANK
GATHER MEMVAR
BROWSE

The following example uses GATHER along with the NAME clause to copy data to a new record in a table. After the table Test is created, SCATTER is used to create an object with properties based on the fields in the table. The object's properties are then assigned values and a new blank record is added to the table.

CREATE TABLE Test FREE ;
   (Object C(10), Color C(16), SqFt n(6,2))

SCATTER NAME oTest BLANK
oTest.Object="Box"
oTest.Color="Red"
oTest.SqFt=12.5
APPEND BLANK
GATHER NAME oTest
RELEASE oTest
BROWSE

See Also

APPEND FROM ARRAY | COPY TO ARRAY | DIMENSION | SCATTER