How to DIMENSION an Array Correctly for APPEND FROM ARRAY

Last reviewed: June 27, 1995
Article ID: Q119250
The information in this article applies to:
  • Microsoft FoxPro for Windows, versions 2.5x, 2.6, 2.6a
  • Microsoft FoxPro for MS-DOS, versions 2.0, 2.5x, 2.6, 2.6a

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


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: June 27, 1995
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.