How to DIMENSION an Array Correctly for APPEND FROM ARRAY

ID: Q119250

The information in this article applies to:

SUMMARY

How you DIMENSION an array sometimes does make a difference; that is, Myarray(1) is not always the same as Myarray(1,1). While the manner in which an array is DIMENSIONed normally does not make a difference, the APPEND FROM ARRAY command does require the array to be DIMENSIONed, including both the row and column references.

MORE INFORMATION

To illustrate the differences DIMENSIONing makes, use the code sample below with any table that has the following structure:

   <Fieldname> C (10)

Code Sample

   *Create the array.
   PUBLIC ARRAY Myarray(3)
   Myarray(1)="one"
   Myarray(2)="two"
   Myarray(3)="three"
   *Try to bring in the array as new records in a table.
   APPEND FROM ARRAY Myarray

In the first character field of your table, "one" (without the quotation marks) is brought in; in the second character field, "two" is brought in; in the third character field, "three" is brought in. The next row is ignored.

To correct this problem, use the following code instead:

   *Create the array.
   PUBLIC ARRAY Myarray(3)
   *Redimension the array to include both row and column references.
   DIMENSION Myarray(3,1)
   Myarray(1)="one"
   Myarray(2)="two"
   Myarray(3)="three"
   *Try to bring in the array as new records in a table.
   APPEND FROM ARRAY Myarray

With this code, "one", "two", and "three" are brought in in the same field in successive records as they should be.

Additional reference words: FoxDos FoxWin 2.00 2.50 2.50a 2.50b 2.60 2.60a KBCategory: kbprg KBSubcategory: FxprgGeneral

Last Reviewed: June 27, 1995