to       Maurice Frank
Subject: Foxpro Arrays

* Written by Paul Holmes
* 202 Greensway
* Peachtree City, Ga. 30269
* 404-487-5850
This is a quick example of some array work I have done with
Foxpro 2.0

private asarray,astemp,ar_cont,af_cont
********************************************************************
** asarray is the s-type array, atemp is a temp array, ar_cont ;
the record count in the s-type array, af_cont is the field count in ;
both the s and temp array.  Both arrays have space(0) initiated.
*******************************************************************
store 25 to ar_cont
store  9 to af_cont
DIMENSION asarray(ar_cont,af_cont)
DIMENSION atemp(1,af_cont)
STORE SPACE(0) TO asarray,atemp

*****************************************************************
* As a full record is accumulated it is placed in the s-type array
* by looking in the first position of each record for space(0). 
* When found, the nine fields in this example are stored
* to the array. (Be sure that none of the fields you store to the
* array are space(0).)
*****************************************************************
PROCEDURE store_to_array
SET EXACT ON && so you wont take just any character field
FOR pos1=1 TO ar_cont && looking at all records
    IF asarray(pos1,1)=space(0)  && but only the first field
       STORE field1   TO asarray(pos1,1)
       STORE field2   TO asarray(pos1,2)
       STORE field3   TO asarray(pos1,3)
       STORE field4   TO asarray(pos1,4)
       STORE field5   TO asarray(pos1,5)
       STORE field6   TO asarray(pos1,6)
       STORE field7   TO asarray(pos1,7)
       STORE field8   TO asarray(pos1,8)
       STORE field9   TO asarray(pos1,9)
       pos1=ar_cont && so you will stop loking for a space(0)
       * then reset all the field? to space(1)
    ENDIF
ENDFOR
SET EXACT OFF       
RETURN
***************************************************************
* In my use of this procedure, I must find a particular record from
* the s-type array, retrieve it and place it into the atemp array
* both to edit some fields and then store it to one of six 
* databases.  I look for two matching fields next to each other
* in this case fields 4 and 5
**************************************************************
PROCEDURE find_match
FOR pos2=1 TO ar_cont && search all the records
    IF asarray(pos2,4)=memvar1 .AND. asarray(pos2,5)=memvar2
      nelement=i*9-8 && to find the first field to copy
      =ACOPY(asarray,atemp,nelement,af_cont) && copy the 9 fields;
                                          in my case to atemp
      FOR pos3=1 To 9       
          STORE SPACE(0) TO asarray(pos2,pos3)  && to put space();
                                              back in the array
      ENDFOR                                        
      pos2=ar_cont  && to stop looking
    ENDIF
ENDFOR    
RETURN
   

***************************************************

* Once I get the atemp array modified as required and determine
* which database receives it, it is simply

SELECT (database)
APPEND FROM ARRAY atemp
STORE space(0) to atemp



