How to Display More than One Record at a TimeLast reviewed: April 30, 1996Article ID: Q120290 |
The information in this article applies to:
SUMMARYYou can view more than one record at a time within a screen by using the BROWSE command, but sometimes you may want to have this ability without using BROWSE. This article shows you how you can use code to create your own screen.
MORE INFORMATIONThe following code demonstrates one method you can use to create your own screen. For practical application, you will need to increase the number of @..GET commands and make the array larger than demonstrated in this example. With FONT clauses and higher resolution video drivers under FoxPro for Windows, you could display quite a few more records at one time. This example displays only two records at a time. SET TALK OFF SET SAFETY OFF SET DEFAULT TO d:\fpw26\tutorial && path containing INVOICES.DBFUSE Invoices INDEX ON ino TAG Ino ON ERROR DO brerr WITH ERROR() && To trap for EOF(). DIMENSION myray(2,5) && Creates an empty 10 element && array for later use. GO TOP && Start at top of table, to && fill initial array.*** Place five fields of the first two records into the array: COPY NEXT 2 TO ARRAY myray FIELDS ino, cno, idate, itotal, salesman *** Define the window to place the @..GETs, and @..SAYs: DEFINE WINDOW brwin ; AT 0.000, 0.000 ; SIZE 7.813,75.429 ; FONT "MS Sans Serif", 8 ; FLOAT ; NOCLOSE ; MINIMIZE ; SYSTEM*** Intialize and declare variables for later use: REGIONAL m.choice, m.quitting m.quitting = .F. m.choice = "OK" *** Activate the window 'Brwin' and create all the @..SAYs *** and @..GETs to create two rows of five fields and the *** button controls: ACTIVATE WINDOW brwin @ 0.250,8.571 SAY "Ino" ; FONT "MS Sans Serif", 8 ; STYLE "BT"*** The @...GETs below contain the array elements. @ 1.688,9.000 GET myray(1,1) ; SIZE 1.000,4.143 ; DEFAULT 0 ; FONT "MS Sans Serif", 8 ; PICTURE "@K"@ 0.250,20.571 SAY "Cno" ; FONT "MS Sans Serif", 8 ; STYLE "BT"@ 1.688,19.286 GET myray(1,2) ; SIZE 1.000,7.714 ; DEFAULT " " ; FONT "MS Sans Serif", 8 ; PICTURE "@K"@ 0.250,32.571 SAY "Idate" ; FONT "MS Sans Serif", 8 ; STYLE "BT"@ 1.688,31.286 GET myray(1,3) ; SIZE 1.000,7.857 ; DEFAULT { / / } ; FONT "MS Sans Serif", 8 ; PICTURE "@K"@ 0.250,44.571 SAY "Itotal" ; FONT "MS Sans Serif", 8 ; STYLE "BT"@ 1.688,43.286 GET myray(1,4) ; SIZE 1.000,8.143 ; DEFAULT 0 ; FONT "MS Sans Serif", 8 ; PICTURE "@K"@ 0.250,54.857 SAY "Salesman" ; FONT "MS Sans Serif", 8 ; STYLE "BT"@ 1.688,57.000 GET myray(1,5) ; SIZE 1.000,4.429 ; DEFAULT " " ; FONT "MS Sans Serif", 8 ; PICTURE "@K"@ 3.250,9.000 GET myray(2,1) ; SIZE 1.000,4.143 ; DEFAULT 0 ; FONT "MS Sans Serif", 8 ; PICTURE "@K"@ 3.250,19.286 GET myray(2,2) ; SIZE 1.000,7.714 ; DEFAULT " " ; FONT "MS Sans Serif", 8 ; PICTURE "@K"@ 3.250,31.286 GET myray(2,3) ; SIZE 1.000,7.857 ; DEFAULT { / / } ; FONT "MS Sans Serif", 8 ; PICTURE "@K"@ 3.250,43.286 GET myray(2,4) ; SIZE 1.000,8.143 ; DEFAULT 0 ; FONT "MS Sans Serif", 8 ; PICTURE "@K"@ 3.250,57.000 GET myray(2,5) ; SIZE 1.000,4.429 ; DEFAULT " " ; FONT "MS Sans Serif", 8 ; PICTURE "@K"*** Here is the push button containing controls to display the *** next two records, the top two records, the previous two *** records, the bottom two records, or to exit the screen. See *** the VALID function Control() below. @ 5.250,1.714 GET choice ; PICTURE "@*HN \NEXT;TO\P 2;\PREVIOUS;\BOTTOM 2;E\XIT" ; SIZE 1.625,11.375,0.500 ; DEFAULT 1 ; FONT "MS Sans Serif", 8 ; STYLE "B" ; VALID control()IF NOT WVISIBLE("Brwin") ACTIVATE WINDOW brwinENDIF READ CYCLE *** Clear the ON ERROR setting, and release the window Brwin *** after the READ is cleared. ON ERROR RELEASE WINDOW brwin *** Supporting Procedures and Functions: *** This error code traps one thing. It is looking for *** an EOF error. If one is found, the last two records are *** displayed, with the WAIT WINDOW message. PROCEDURE brerr PARAMETER errid IF errid=4 WAIT WINDOW "The last two records are already being ; displayed!" NOWAIT GO BOTTOM SKIP -1 COPY NEXT 2 TO ARRAY myray ; FIELDS ino, cno, idate, itotal, salesman SHOW GETSENDIF RETURN *** Control code for the above push button: FUNCTION control && CHOICE VALID#REGION 1 DO CASE CASE m.choice = "NEXT" && Displays the next two records. SKIP COPY NEXT 2 TO ARRAY myray FIELDS ino, cno, idate, ; itotal, salesman SHOW GETS CASE m.choice = "TOP 2" && Displays the top two records. GO TOP COPY NEXT 2 TO ARRAY myray FIELDS ino, cno, idate, ; itotal, salesman SHOW GETS CASE m.choice = "PREVIOUS" && Displays the previous two && records. SKIP -3 COPY NEXT 2 TO ARRAY myray FIELDS ino, cno, idate, ; itotal, salesman SHOW GETS CASE m.choice = "BOTTOM 2" && Displays the final two && records. GO BOTTOM SKIP -1 COPY NEXT 2 TO ARRAY myray FIELDS ino, cno, idate, ; itotal, salesman SHOW GETS CASE m.choice = "EXIT" && Exits the screen. WAIT WINDOW "BYE-BYE" NOWAIT m.idlequit = .T. m.quitting = .T. CLEAR READ ENDCASERETURN
REFERENCES"Interface Guide," version 2.0 (MS-DOS), Chapter 12 "User's Guide," version 2.5x, 2.6, 2.6a (MS-DOS), Chapter 12 "User's Guide," version 2.5x, 2.6, 2.6a (Windows), Chapter 11
|
Additional reference words: VFoxWin 3.00 FoxDos FoxWin 2.00 2.50 2.50a
© 1998 Microsoft Corporation. All rights reserved. Terms of Use. |