DOCUMENT:Q133455 15-FEB-2000 [foxpro] TITLE :How to Create an Array of Structures in Visual FoxPro PRODUCT :Microsoft FoxPro PROD/VER:WINDOWS:3.0 OPER/SYS: KEYWORDS: ====================================================================== ------------------------------------------------------------------------------- The information in this article applies to: - Microsoft Visual FoxPro for Windows, version 3.0 ------------------------------------------------------------------------------- SUMMARY ======= User-defined structures (similar to user-defined types in Visual Basic or structs in C) are possible by using the CUSTOM Class. This article shows by example how to create a user-defined array of structures. MORE INFORMATION ================ The following code sample illustrates how to define an array of structures. The structure itself is defined in a custom class called sMyStruct. The code reads the values from the Products table and populates the array of structures. Code Sample ----------- OPEN DATABASE C:\VFP\SAMPLES\DATA\TESTDATA.DBC USE C:\VFP\SAMPLES\DATA\PRODUCTS.DBF GO TOP && Start from the top PUBLIC DIMENSION oMyStruct(10) && Define the array of structures FOR i=1 to 10 oMyStruct(i)=CREATEOBJECT("sMyStruct") oMyStruct(i).Product_Name=PRODUCTS.Prod_name oMyStruct(i).Engineer_Name=PRODUCTS.Eng_name oMyStruct(i).Cost_Per_Unit=PRODUCTS.Unit_cost ?oMyStruct(i).Product_Name ?oMyStruct(i).Engineer_Name ?oMyStruct(i).Cost_Per_Unit SKIP ENDFOR DEFINE CLASS sMyStruct AS CUSTOM Product_Name='' Engineer_Name='' Cost_Per_Unit=0 ENDDEFINE Additional query words: struct VB VFoxWin ====================================================================== Keywords : Technology : kbVFPsearch kbAudDeveloper kbVFP300 Version : WINDOWS:3.0 ============================================================================= 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 2000.