READ Code Examples for FoxPro

Last reviewed: April 29, 1996
Article ID: Q88328
The information in this article applies to:
  • Microsoft Visual FoxPro for Windows, version 3.0
  • 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
  • Microsoft FoxPro for Macintosh, versions 2.5x, 2.6a

The following sample program demonstrates the various types of READ statements.

*:********************************************************************* *:

*:        Program: BRREAD.PRG
*:
*:         System: FoxPro 2.0 READ example
*:      Copyright (c) 1991, Microsoft Corporation
*:
*: Procs & Fncts: INITWIN1
*:               : CLEARSCR
*:               : UDF1()
*:               : UDF2()
*:               : UDF3()
*:               : UDF5()
*:               : UDF6()
*:               : UDF7()
*:               : UDF4()
*:
*:          Calls: INITWIN1       (procedure in BRREAD.PRG)
*:               : CLEARSCR       (procedure in BRREAD.PRG)
*:               : UDF1()         (function  in BRREAD.PRG)
*:               : UDF2()         (function  in BRREAD.PRG)
*:               : UDF3()         (function  in BRREAD.PRG)
*:               : UDF5()         (function  in BRREAD.PRG)
*:               : UDF6()         (function  in BRREAD.PRG)
*:               : UDF7()         (function  in BRREAD.PRG)
*:
*:      Documented 04/08/91 at 19:54               FoxDoc  version 2.0
*:********************************************************************* SET COLOR OF SCHEME 1 TO W+/B CLEAR CLEAR ALL @ 4,4 SAY 'Loading BRREAD.PRG please wait...' CLOSE ALL SET ESCA ON SET CURSOR OFF SET STAT OFF SET MESSAGE TO " Hit ESCAPE to Continue" PUBLIC get1, get2, get3, get4

SET COLOR OF SCHEME 1 TO W+/BG string='FoxPro 2.0 READ examples' @ 0,0 SAY SPACE(80) @ 0,(80-LEN(string))/2 SAY string

DEFINE WINDOW xcommand FROM 20,2 TO 22,77;

   COLOR W+/R,W+/R,W+/R,W+/R,W+/R TITLE '  Example of Command:  '
DEFINE WINDOW win1 FROM 2,4 TO 14,36 COLOR W+/BR,N/W,W+/BR,GR+/BR,W/BR;
   TITLE '  Window One  '
DEFINE WINDOW win2 FROM 2,44 TO 14,76 COLOR W+/BR,N/W,W+/BR,GR+/BR,W/BR;
   TITLE '  Window Two  '

***************************************************************************
*  Simple READ CYCLE in one window.                                       *
***************************************************************************

ACTIVATE WINDOW xcommand @ 0,1 SAY 'READ CYCLE COLOR ,w+/b'

DO initwin1 @ 2,2 SAY 'This is GET #1:' GET get1 @ 3,2 SAY 'This is GET #2:' GET get2 @ 4,2 SAY 'This is GET #3:' GET get3 @ 5,2 SAY 'This is GET #4:' GET get4

SET CURSOR ON READ cycle COLOR ,W+/B SET CURSOR OFF DO clearscr

***************************************************************************

*  READ CYCLE OBJECT in one window.                                       *
*************************************************************************** ACTIVATE WINDOW xcommand CLEAR @ 0,1 SAY 'READ CYCLE COLOR ,w+/b OBJECT 3'

DO initwin1 @ 2,2 SAY 'This is GET #1:' GET get1 @ 3,2 SAY 'This is GET #2:' GET get2 @ 4,2 SAY 'This is GET #3:' GET get3 @ 5,2 SAY 'This is GET #4:' GET get4

SET CURSOR ON READ cycle COLOR ,W+/B object 3 SET CURSOR OFF DO clearscr

***************************************************************************

*  READ CYCLE OBJECT with radio buttons.                                  *
*************************************************************************** ACTIVATE WINDOW xcommand CLEAR @ 0,1 SAY 'READ CYCLE COLOR ,w+/b OBJECT 7 (with radio buttons)'

DEFINE WINDOW win1 FROM 2,4 TO 14,76 COLOR W+/BR,N/W,W+/BR,GR+/BR,W/BR;

   TITLE '  Window One  '

DO initwin1 @ 2,2 SAY 'This is GET #1:' GET get1 @ 3,2 SAY 'This is GET #2:' GET get2 @ 4,2 SAY 'This is GET #3:' GET get3 @ 5,2 SAY 'This is GET #4:' GET get4

STORE 1 TO choice @ 2,42 GET choice FUNCTION '*R Ford;Chevy;Pontiac;Toyota';

   COLOR ,,,,,W+/B,,,W+/BR

SET CURSOR ON READ cycle COLOR ,W+/B object 7 SET CURSOR OFF DO clearscr

***************************************************************************

*  READ CYCLE spanning 2 windows.                                         *
*************************************************************************** ACTIVATE WINDOW xcommand CLEAR @ 0,1 SAY 'READ CYCLE COLOR ,w+/b (spanning 2 windows)'

DEFINE WINDOW win1 FROM 2,4 TO 14,36 COLOR W+/BR,N/W,W+/BR,GR+/BR,W/BR;

   TITLE '  Window One  '

DO initwin1 @ 2,2 SAY 'This is GET #1:' GET get1 @ 3,2 SAY 'This is GET #2:' GET get2 ACTIVATE WINDOW win2 @ 2,2 SAY 'This is GET #3:' GET get3 @ 3,2 SAY 'This is GET #4:' GET get4

SET CURSOR ON READ cycle COLOR ,W+/B SET CURSOR OFF DO clearscr

***************************************************************************

*  ACTIVATE clause on READ CYCLE spanning 2 windows.                      *
***************************************************************************

DEFINE WINDOW win1 FROM 2,4 TO 10,36 COLOR W+/BR,N/W,W+/BR,GR+/BR,W/BR;

   TITLE '  Window One  '

DEFINE WINDOW win2 FROM 2,44 TO 10,76 COLOR W+/BR,N/W,W+/BR,GR+/BR,W/BR;
   TITLE '  Window Two  '

ACTIVATE WINDOW xcommand CLEAR @ 0,1 SAY 'READ CYCLE COLOR ,w+/b ACTIVATE UDF1()'

DO initwin1 @ 2,2 SAY 'This is GET #1:' GET get1 @ 3,2 SAY 'This is GET #2:' GET get2 ACTIVATE WINDOW win2 @ 2,2 SAY 'This is GET #3:' GET get3 @ 3,2 SAY 'This is GET #4:' GET get4

SET CURSOR ON READ cycle COLOR ,W+/B ACTIVATE udf1() SET CURSOR OFF DO clearscr

***************************************************************************

*  DEACTIVATE clause on READ CYCLE spanning 2 windows.                    *
*************************************************************************** ACTIVATE WINDOW xcommand CLEAR @ 0,1 SAY 'READ CYCLE COLOR ,w+/b DEACTIVATE UDF2()'

ACTIVATE WINDOW win2 CLEAR

DO initwin1 @ 2,2 SAY 'This is GET #1:' GET get1 @ 3,2 SAY 'This is GET #2:' GET get2 ACTIVATE WINDOW win2 @ 2,2 SAY 'This is GET #3:' GET get3 @ 3,2 SAY 'This is GET #4:' GET get4 SET CURSOR ON READ cycle COLOR ,W+/B DEACTIVATE udf2() SET CURSOR OFF DO clearscr

***************************************************************************

*  READ CYCLE VALID spanning 2 windows.                                   *
***************************************************************************

ACTIVATE WINDOW xcommand CLEAR @ 0,1 SAY 'READ CYCLE COLOR ,w+/b VALID UDF3()'

ACTIVATE WINDOW win2 CLEAR

DO initwin1 @ 2,2 SAY 'This is GET #1:' GET get1 @ 3,2 SAY 'This is GET #2:' GET get2 @ 4,2 SAY 'RDLEVEL() = ' + LTRIM(STR(rdlevel())) ACTIVATE WINDOW win2 @ 2,2 SAY 'This is GET #3:' GET get3 @ 3,2 SAY 'This is GET #4:' GET get4 @ 4,2 SAY 'RDLEVEL() = ' + LTRIM(STR(rdlevel()))

SET CURSOR ON READ cycle COLOR ,W+/B VALID udf3() SET CURSOR OFF DO clearscr

***************************************************************************

*  READ CYCLE WHEN spanning 2 windows.                                    *
***************************************************************************

ACTIVATE WINDOW xcommand CLEAR @ 0,1 SAY 'READ CYCLE COLOR ,w+/b WHEN UDF5()'

ACTIVATE WINDOW win2 CLEAR

DO initwin1 @ 2,2 SAY 'This is GET #1:' GET get1 @ 3,2 SAY 'This is GET #2:' GET get2 @ 4,2 SAY 'RDLEVEL() = ' + LTRIM(STR(rdlevel())) ACTIVATE WINDOW win2 @ 2,2 SAY 'This is GET #3:' GET get3 @ 3,2 SAY 'This is GET #4:' GET get4 @ 4,2 SAY 'RDLEVEL() = ' + LTRIM(STR(rdlevel()))

SET CURSOR ON READ cycle COLOR ,W+/B WHEN udf5() SET CURSOR OFF DO clearscr

***************************************************************************

*  READ CYCLE SHOW (refreshing SAYs)..                                    *
***************************************************************************

STORE SPACE(10) TO get1, get2, get3, get4 DEFINE WINDOW win1 FROM 2,0 TO 10,24 COLOR W+/BR,N/W,W+/BR,GR+/BR,W/BR;

   TITLE '  Window One  '
DEFINE WINDOW win2 FROM 2,26 TO 24,79 COLOR W+/BG,N/W,W+/BG,GR+/BG,W+/BG;
   TITLE '  Source Code  '
DEFINE WINDOW xcommand FROM 15,0 TO 20,24;
   COLOR W+/R,W+/R,W+/R,W+/R,W+/R TITLE 'Example of Command: '
ACTIVATE WINDOW xcommand CLEAR @ 1,3 SAY 'READ CYCLE SHOW' @ 2,2 SAY '(with SAY refresh)'

mamount1=0 mamount2=0 mtotal =0

ACTIVATE WINDOW win2 TEXT

  mAMOUNT1=0
  mAMOUNT2=0
  mTOTAL  =0
  strAMOUNT1="Amount 1:"
  strAMOUNT2="Amount 2:"

  set echo off
  set talk off

  @ 2,2 say strAMOUNT1 get mAMOUNT1 valid UDF6()
  @ 3,2 say strAMOUNT2 get mAMOUNT2 valid UDF6()
  @ 4,2 say '   Total: '+ str(mTOTAL)

  read cycle show UDF7()
  return

  func UDF6
  Wait window "in valid of read"
  mTOTAL=mAMOUNT1+mAMOUNT2
  show gets
  return .t.

  func UDF7
  @ 4,12 say str(mTOTAL)
  return .t.
ENDTEXT

ACTIVATE WINDOW win1 set echo off set talk off

strAMOUNT1="Amount 1:" strAMOUNT2="Amount 2:"

@ 2,2 SAY strAMOUNT1 GET mamount1 VALID udf6() @ 3,2 SAY strAMOUNT2 GET mamount2 VALID udf6()

@ 4,2  SAY '   Total: '+ STR(mtotal)

SET CURSOR ON READ cycle show udf7() SET CURSOR OFF

ACTIVATE SCREEN SET COLOR OF SCHEME 1 TO W+/B CLEAR CLEAR ALL CLOSE ALL SET MESSAGE TO RETURN

*** EOP: BRREAD.PRG

*!********************************************************************* *!

*!       Function: UDF1()
*!
*!      Called by: BRREAD.PRG
*!
*!********************************************************************* FUNC udf1 DEFI WINDOW win3 FROM 14,2 TO 18,77;
   COLOR W+/BG,W+/BG,W+/BG,W+/BG,W+/BG;
   TITLE  '  From the FoxPro 2.0 Docs:  ';
   footer '  Press any key to continue...  '

ACTIVATE WINDOW win3 @ 0,1 SAY 'The ACTIVATE clause is executed when READ is issued or whenever' @ 1,1 SAY 'the current READ window changes. ACTIVATE may be viewed as a' @ 2,1 SAY 'window level WHEN clause' =INKEY(0) RELEASE WINDOW win3 RETURN .T.

*!********************************************************************* *!

*!       Function: UDF2()
*!
*!      Called by: BRREAD.PRG
*!
*!********************************************************************* FUNC udf2 DEFI WINDOW win3 FROM 14,2 TO 18,77;
   COLOR W+/BG,W+/BG,W+/BG,W+/BG,W+/BG;
   TITLE  '  From the FoxPro 2.0 Docs:  ';
   footer '  Press any key to continue...  '

ACTIVATE WINDOW win3 @ 0,1 SAY 'The DEACTIVATE clause is executed whenever you attempt to bring' @ 1,1 SAY 'forward (activate) another READ window. DEACTIVATE may be' @ 2,1 SAY 'viewed as a window level VALID clause' =INKEY(0) RELEASE WINDOW win3 RETURN .T.

*!********************************************************************* *!

*!       Function: UDF3()
*!
*!      Called by: BRREAD.PRG
*!
*!          Calls: UDF4()         (function  in BRREAD.PRG)
*!
*!********************************************************************* FUNC udf3 DEFI WINDOW win3 FROM 14,2 TO 18,77;
   COLOR W+/BG,W+/B,W+/BG,W+/BG,W+/BG;
   TITLE  '  Alert!  '

ACTIVATE WINDOW win3 X='N' @ 2,1 SAY 'Exit this READ? (Y/N):' GET X PICT '!'

SET CURSOR ON READ WHEN udf4() SET CURSOR OFF

RELEASE WINDOW win3 IF X = 'Y'

   RETURN .T.
ELSE
   RETURN .F.
ENDIF

*!********************************************************************* *!

*!       Function: UDF4()
*!
*!      Called by: UDF3()         (function  in BRREAD.PRG)
*!               : UDF5()         (function  in BRREAD.PRG)
*!
*!********************************************************************* FUNC udf4 @ 0,1 SAY 'RDLEVEL() = ' + LTRIM(STR(rdlevel())) RETURN .T.

*!********************************************************************* *!

*!       Function: UDF5()
*!
*!      Called by: BRREAD.PRG
*!
*!          Calls: UDF4()         (function  in BRREAD.PRG)
*!
*!********************************************************************* FUNC udf5 DEFI WINDOW win3 FROM 14,2 TO 18,77;
   COLOR W+/BG,W+/B,W+/BG,W+/BG,W+/BG;
   TITLE  '  Alert!  '

ACTIVATE WINDOW win3 X='Y' @ 0,1 SAY 'RDLEVEL() = ' + LTRIM(STR(rdlevel())) @ 2,1 SAY 'Enter this READ? (Y/N):' GET X PICT '!'

SET CURSOR ON READ WHEN udf4() SET CURSOR OFF

RELEASE WINDOW win3 IF X = 'Y'

   RETURN .T.
ELSE
   RETURN .F.
ENDIF

*!********************************************************************* *!

*!       Function: UDF6()
*!
*!      Called by: BRREAD.PRG
*!
*!********************************************************************* FUNC udf6

mtotal=mamount1+mamount2 SHOW GETS RETURN .T.

*!********************************************************************* *!

*!       Function: UDF7()
*!
*!      Called by: BRREAD.PRG
*!
*!********************************************************************* FUNC udf7 @ 4,12 SAY STR(mtotal) RETURN .T.

*!********************************************************************* *!

*!      Procedure: CLEARSCR
*!
*!      Called by: BRREAD.PRG
*!
*!********************************************************************* PROC clearscr SET COLOR OF SCHEME 1 TO W+/B @ 1,0 CLEAR RETURN

*!********************************************************************* *!

*!      Procedure: INITWIN1
*!
*!      Called by: BRREAD.PRG
*!
*!********************************************************************* PROC initwin1 STORE SPACE(10) TO get1, get2, get3, get4 ACTIVATE WINDOW win1 CLEAR RETURN *: EOF: BRREAD.PRG


Additional reference words: FoxDos VFoxWin FoxWin FoxMac 2.00 2.50 2.50a
2.50b 3.00 2.50c 2.60 2.60a
KBCategory: kbprg kbcode
KBSubcategory: FxprgRead


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