DOCUMENT:Q191923 19-JUN-2002 [foxpro] TITLE :PRB: COPY TO ARRAY Causes Insufficient Memory Error PRODUCT :Microsoft FoxPro PROD/VER::5.0,5.0a,6.0,7.0 OPER/SYS: KEYWORDS: ====================================================================== ------------------------------------------------------------------------------- The information in this article applies to: - Microsoft Visual FoxPro for Windows, versions 5.0, 5.0a, 6.0, 7.0 ------------------------------------------------------------------------------- SYMPTOMS ======== Using the COPY TO ARRAY command to copy fields to an array can cause an insufficient memory error in Visual FoxPro 5.x and 6.0. If the number of fields copied to the array multiplied by the number of records in the database is greater than 65000, then an insufficient memory error occurs if the array is not previously defined. CAUSE ===== The array was not dimensioned prior to use. RESOLUTION ========== Here are three workarounds for this problem: - Instead of using the COPY TO ARRAY command, use a SELECT statement. For example: SELECT * FROM mytest where name2 = "WY" INTO ARRAY myarray - Dimension the array, prior to use, so that it is large enough to contain the data. For example: DIMENSION myarray(30,10) If the array is already defined, an error will not occur. If the dimensions of the array do not match the data, the array will not be re-dimensioned to match the data by the copy command and data can be lost. - Use an ON ERROR handle to check for Error 43 and ignore the error message. STATUS ====== Microsoft has confirmed this to be a problem in the Microsoft products listed at the beginning of this article. MORE INFORMATION ================ If you ignore the insufficient memory error message, the array is created anyway. Steps to Reproduce Behavior --------------------------- 1. Create a program (.prg) file. 2. Place the following code in the .prg file: CREATE TABLE mytest (name1 c(10), name2 c(2), name3 c(5),; name4 c(5), name5 c(5)) FOR i = 1 to 40 INSERT INTO mytest (name1, name2, name3, name4, name5); VALUES (SYS(2015), "WA", "WORLD", "HELLO", "TEST" ) ENDFOR FOR i = 1 to 20 INSERT INTO mytest (name1, name2, name3, name4, name5); VALUES (SYS(2015), "WY", "WORLD", "SMITH", "TEST1") ENDFOR FOR i = 1 to 15000 INSERT INTO mytest (name1, name2, name3, name4, name5); VALUES (SYS(2015), "MA", "WORLD", "SMITH", "TEST1") ENDFOR INDEX ON name2 TAG name2 SET ORDER TO name2 SEEK "WY" IF FOUND() WAIT WINDOW "RECORD FOUND" NOWAIT COPY TO ARRAY myarray WHILE name2='WY' ELSE RETURN ENDIF 3. Save and run the program. NOTE: When the Wait window appears, a Program Error dialog displays with the following error: There is not enough memory to complete this operation. REFERENCES ========== Microsoft FoxPro Help, serach on: "COPY TO ARRAY" Microsoft FoxPro Help, search on: "DIMENSION" Additional query words: kbXBase kbVFp600 kbVFp500a kbVFp500 ====================================================================== Keywords : Technology : kbVFPsearch kbAudDeveloper kbVFP500 kbVFP600 kbVFP700 kbVFP500a Version : :5.0,5.0a,6.0,7.0 Issue type : kbprb Solution Type : kbnofix ============================================================================= 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. Copyright Microsoft Corporation 2002.