PRB: Pressing ENTER on a Check Box Runs Default Push Button

Last reviewed: June 27, 1995
Article ID: Q125005
The information in this article applies to:
  • Microsoft FoxPro for Windows, versions 2.5, 2.5a, 2.5b, 2.6, 2.6a

SYMPTOMS

If you press the ENTER key while the insertion point is positioned in a check box, code unrelated to the check box executes.

CAUSE

In the screen set, you have a push button defined as a default push button.

WORKAROUND

Use one of the following workarounds:

  • Do not define a default push button.

    -or-

  • Program a trap to track where the call originated from. Use the trap to determine if the code related to the default push button should be run.

STATUS

This behavior is by design.

MORE INFORMATION

According to the FoxPro for Windows Help file:

A default Push Button is typically used to exit a data-entry screen, dialog, or routine and accept any changes made in the screen, dialog, or routine.

If a screen has a default Push Button defined, the code of the Valid or When clauses of that button is executed when the ENTER key is pressed while on a Check box. As a result, the screen may behave in an unanticipated way with no indication as to the source of the behavior. Code in the Valid clause of the Check Box is not executed.

To create a default Push Button, place a backslash and an exclamation point (\!) before the Push Button's prompt. The following example specifies the OK button as the default Push Button:

   STORE 1 TO mchoice
   @ 2,2 GET mchoice FUNCTION '*  \!OK;Cancel'
   READ

In FoxPro for Windows, the default button is identified by a thick black border around the button. The default button is automatically chosen when you press the ENTER key, CTRL+ENTER, or CTRL+W.

Also, according to the Help file:

The KEYCOMP setting determines the behavior of default Push Buttons in FoxPro for Windows in the following ways:

  • If you SET KEYCOMP TO DOS, the behavior of the default Push Button is the same as the behavior of a default Push Button in FoxPro for MS-DOS.
  • If you SET KEYCOMP TO WINDOWS, the default Push Button changes as you move between buttons. The push button specified with \! is the default button when objects besides Push Buttons are active. When a Push Button is active, it becomes the default Push Button.

Steps to Reproduce Behavior

Create and run a program containing the following code:

   DEFINE WINDOW testwin ;
        AT 0.000, 0.000 ;
        SIZE 10.000,67.000 ;
        FONT "MS Sans Serif", 8 ;
        FLOAT ;
        NOCLOSE ;
        MINIMIZE ;
        SYSTEM

   MOVE WINDOW testwin CENTER

   ACTIVATE WINDOW testwin

   @ 2.800,12.400 GET getfield ;
        SIZE 1.000,16.000 ;
        DEFAULT " " ;
        FONT "MS Sans Serif", 8 ;
        PICTURE "@K"
   @ 2.900,33.500 GET cbox ;
        PICTURE "@*C check box" ;
        SIZE 1.300,14.500 ;
        DEFAULT 0 ;
        FONT "MS Sans Serif", 8 ;
        STYLE "BT"
   @ 6.500,19.500 GET button ;
     PICTURE "@*HN \!Quit" ;
     SIZE 1.700,7.500,0.750 ;
     DEFAULT 1 ;
     FONT "MS Sans Serif", 8 ;
     STYLE "B" ;
     VALID byebye()

   READ CYCLE
   RELEASE WINDOW testwin

   FUNCTION byebye     &&  Button VALID
   WAIT WINDOW "Quitting..."


Additional reference words: FoxWin 2.50 2.50a 2.50b 2.60 2.60a
KBCategory: kbui kbprg kbprb
KBSubcategory: FxotherGeneral


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