BUG: ON KEY LABEL <Keyname> EXIT Fails with DO WHILE .T. Loop

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

SYMPTOMS

In the following code example, pressing CTRL+C or any other key combination that is defined to terminate the DO WHILE loop will cause a "Nesting error" message. In this example, CTRL+C has been used as a "natural" key combination, although CTRL+D, CTRL+Q, or any other key combination will also produce the same error.

   ON KEY LABEL ctrl+C EXIT
   DO WHILE .T.
      WAIT WINDOW "hello" NOWAIT
   ENDDO

RESOLUTION

To set up a DO WHILE control structure that will terminate when a key combination is pressed, create a variable and initialize it to true (.T.). In the ON KEY LABEL statement, reassign the memory variable to false (.F.).

   memvar = .T.
   ON KEY LABEL ctrl+C memvar = .F.
   DO WHILE memvar
      WAIT WINDOW "HELLO" NOWAIT
   ENDDO

Another way of achieving the same result is shown in this second example. In the following code, VAR1 is initialized to null. When the CTRL+C key combination is pressed, VAR1 is assigned the command to be executed. Until VAR1 is assigned something to do, nothing gets done. Upon assignment, the command is executed and the loop is terminated. This indirection also works for other commands as well.

   var1=""
   ON KEY LABEL ctrl+C var1="EXIT"
   DO WHILE .T.
      WAIT WINDOW "Hello World" NOWAIT
      &var1
   ENDDO

STATUS

Microsoft has confirmed this to be a problem in the Microsoft products listed at the beginning of this article. We are researching this problem and will post new information here in the Microsoft Knowledge Base as it becomes available.


Additional reference words: FoxDos FoxWin buglist2.00 buglist2.50
buglist2.50a buglist2.50b buglist2.60 buglist2.60a 2.00 2.50 2.50a 2.50b
2.60 2.60a errmsg
KBCategory: kbenv kbprg kberrmsg kbbuglist
KBSubcategory: FxenvMemory


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: August 28, 1995
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.