FIX: Using an Array Element as the Counter in a For Loop Fails

Last reviewed: February 20, 1997
Article ID: Q147277
The information in this article applies to:
  • Microsoft Visual FoxPro for Windows, versions 3.0 and 3.0b
  • Microsoft FoxPro for Windows, Versions 2.6 and 2.6a

SYMPTOMS

In FoxPro and Visual FoxPro, attempting to use an array element as the counter variable in a FOR...ENDFOR command results in the error, "Not a numeric expression." If the array hasn't been declared, you may receive the error, "Variable not found."

WORKAROUND

Use a memory variable instead of an array element.

STATUS

Microsoft has confirmed this to be a problem in the Microsoft products listed at the beginning of this article. This problem has been fixed in Visual FoxPro 5.0 for Windows.

MORE INFORMATION

According to the FoxPro and Visual FoxPro language reference, you should be able to use an array element as the counter variable in a FOR...ENDFOR Command.

Steps to Reproduce Problem

Type the following code into a program file:

   DIMENSION aTest[1]

   FOR aTest[1]=1 TO 10
      WAIT WINDOW "This is a test"
   ENDFOR

When you run this program you will receive the error, "Not a numeric expression." If you replace aTest[1] with nMyVar in the FOR statement it will work correctly.


KBCategory: kbprg kbbuglist kbfixlist
KBSubcategory: FxprgGeneral VFoxWin buglist2.60 buglist2.60a buglist3.00
buglist3.00b fixlist5.00
Additional reference words: 2.60 2.60a 3.00 3.00b


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: February 20, 1997
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.