Switching Between a Screen and Browse Using a Single Key

Last reviewed: April 30, 1996
Article ID: Q108682
The information in this article applies to:
  • Microsoft FoxPro for Windows, versions 2.5, 2.5a, and 2.5b
  • Microsoft FoxPro for MS-DOS, versions 2.0, 2.5, 2.5a, and 2.5b

SUMMARY

Some database managers can switch between a single-record screen and a browse-like screen with one keystroke acting as a toggle between the two. Although FoxPro does not have this capability built in, you can simulate this feature programmatically, as demonstrated below.

MORE INFORMATION

The program below is provided as an example of using a single key to switch between a data entry screen and a Browse window in FoxPro.

* This program uses the same VALIDs for both BROWSE and GET fields. * Run this program from the same directory as the TUTORIAL database * 'CUSTOMER.DBF'. Press F2 to switch between the screen and BROWSE.

   IF USED("customer")
      SELECT customer
   ELSE
      IF FILE("CUSTOMER.DBF")
         SELECT 0
         USE customer.dbf
      ELSE
         WAIT WINDOW "NO DATABASE"
         RETURN
      ENDIF
   ENDIF

   DEFINE WINDOW w1 FROM 1,1 TO 19,65 TITLE 'Record view' && main window

   *Now duplicate the main window and create a browse in it:
   DEFINE WINDOW w2 FROM 1,1 TO 19,65                   && browse window
   BROW IN WINDOW w2 TITLE 'Records' ;
      FIELDS cno :v=vcno() :F, company, contact, address, ;
             city, state, zip, phone ;
      NOWAIT
   ACTIVATE WINDOW w2 NOSHOW
   ZOOM WINDOW records MAX

   ACTIVATE WINDOW w1 TOP
   ON KEY LABEL f2 DO switch   && sets up window switching
   ON KEY LABEL esc DO bye

   @ 1,22 SAY "Cno"
   @ 1,27 GET cno SIZE 1.000,7.600 VALID vcno()
   @ 3,2 SAY "Company"
   @ 3,14 GET company SIZE 1.000,32.000
   @ 5,2 SAY "Contact"
   @ 5,14 GET contact SIZE 1.000,31.600
   @ 7,2 SAY "Address"
   @ 7,14 GET address SIZE 1.000,47.600
   @ 9,2 SAY "City"
   @ 9,14 GET city SIZE 1.000,23.600
   @ 11,2 SAY "State"
   @ 11,14 GET state SIZE 1.000,2.800
   @ 13,2 SAY "Zip"
   @ 13,14 GET zip SIZE 1.000,7.600
   @ 15,2 SAY "Phone"
   @ 15,14 GET phone SIZE 1.000,31.600
   READ CYCLE

   **********************************************************
   *                Closing code
   **********************************************************
   RELEASE WINDOW w1
   RELEASE WINDOW w2
   ON KEY LABEL f2

   **********************************************************
   PROCEDURE switch
   **********************************************************
   IF WVISIBLE("w1")
      HIDE WINDOW w1
      SHOW WINDOW w2
   ELSE
      HIDE WINDOW w2
      SHOW WINDOW w1
      SHOW GETS
   ENDIF

   **********************************************************
   PROCEDURE bye
   **********************************************************
   ON KEY LABEL esc
   ACTIVATE WINDOW w1 TOP
   CLEAR READ

   **********************************************************
   FUNCTION vcno && valid for field CNO in both screen and browse
   **********************************************************
   IF ! LEN(ALLTRIM(cno)) > 1
      RETURN .F.
   ELSE
      RETURN .T.
   ENDIF


Additional reference words: FoxDos FoxWin 2.00 2.50 2.50a 2.50b on
key
label
KBCategory: kbprg kbcode
KBSubcategory: FxprgBrowse


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: April 30, 1996
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.