Microsoft KB Archive/276287

= PRB: SET FORMAT File Scrolls to End of Table in Visual FoxPro =

Article ID: 276287

Article Last Modified on 8/27/2002

-

APPLIES TO


 * Microsoft Visual FoxPro 5.0 Standard Edition
 * Microsoft Visual FoxPro 5.0a
 * Microsoft Visual FoxPro 6.0 Professional Edition

-



This article was previously published under Q276287



SYMPTOMS
Visual FoxPro offers a level of backward compatibility with files from Dbase. In some cases, you might find that Dbase Format (.fmt) files behave erratically by scrolling to the end the table, as if the Page Down key is being pressed.



CAUSE
Visual FoxPro uses Event Model rather than Foundation READ.



RESOLUTION
There are two recommended workarounds:  The first method is to recreate the format files as native Visual FoxPro forms. The second method requires modifications to the format files. The following code is generated when you create a format file in Dbase, and it varies depending on how the format file was originally designed. To demonstrate this workaround, perform the following steps:   Paste the following code into a program or text file, and save it as Empform.fmt: *-- Format file initialization code

IF SET(&quot;TALK&quot;)=&quot;ON&quot; SET TALK OFF lc_talk=&quot;ON&quot; ELSE lc_talk=&quot;OFF&quot; ENDIF

SET DISPLAY TO EGA25
 * -- This form was created in EGA25 mode

lc_status=SET(&quot;STATUS&quot;) IF lc_status = &quot;OFF&quot; SET STATUS ON ENDIF
 * -- SET STATUS was ON when you went into the Forms Designer.


 * -- @ SAY GETS Processing. --

SET PROCEDURE TO SetKey KeyInit  &&Initializes the keys
 * !* MODIFICATION (1 of 2)
 * !* Set a procedure call to assign keys
 * !* functionality to the PageUp, PageDown and Escape Keys.

@ 1,0 SAY &quot;EMP_ID&quot; @ 1,12 GET emp_id PICTURE &quot;XXXXXX&quot; @ 2,0 SAY &quot;LAST_NAME&quot; @ 2,12 GET lname PICTURE &quot;XXXXXXXXXXXXXXXXXXXX&quot; @ 3,0 SAY &quot;FIRST_NAME&quot; @ 3,12 GET fname PICTURE &quot;XXXXXXXXXX&quot; @ 6,0 SAY &quot;HIRE_DATE&quot; @ 6,12 GET hire_date
 * -- Format Page: 1
 * -- Format file exit code ---

READ CYCLE
 * !* MODIFICATION (2 of 2)
 * !* Establish the READ command to loop around the fields.

IF lc_status = &quot;OFF&quot; && Entered form with status off SET STATUS OFF    && Turn STATUS &quot;OFF&quot; on the way out ENDIF
 * -- SET STATUS was ON when you went into the Forms Designer.

IF lc_talk=&quot;ON&quot; SET TALK ON ENDIF

RELEASE lc_talk,lc_fields,lc_status   Paste the following code into a program or text file, and save it as Setkey.prg: FUNCTION KeyInit ON KEY LABEL PgUp PageUp ON KEY LABEL PgDn PageDown ON KEY LABEL Esc EscFunc ENDFUNC
 * -- EOP: EMPFORM.FMT

FUNCTION PageUp IF !BOF SKIP -1 SHOW GETS ELSE GO TOP ENDIF ENDFUNC

FUNCTION PageDown SKIP IF EOF GO BOTTOM ENDIF SHOW GETS ENDFUNC

FUNCTION EscFunc ON KEY LABEL PgUp ON KEY LABEL PgDn ON KEY LABEL Esc SET STATUS BAR ON   CLEAR CANCEL ENDFUNC   Paste this code into a program or text file, and save it as Main.prg: *!* Creates a sample table CREATE TABLE emp_table (emp_id c(9),fname c(20),lname c(30),hire_date T(8))

INSERT INTO emp_table (emp_id,fname,lname,hire_date); VALUES ('234234325','George','Washington',{^2000/07/01 12:35pm})
 * !* Inserts sample records.

INSERT INTO emp_table (emp_id,fname,lname,hire_date); VALUES ('456432734','Albert','Einstein',{^2000/08/23 4:40pm})

INSERT INTO emp_table (emp_id, fname,lname,hire_date); VALUES ('566753444','Amelia','Earhart',{^2000/10/15 8:00am})

GO TOP

DO empform.fmt &&Calls the Format File USE  Run the program from Visual FoxPro by typing DO MAIN from the Command window and pressing ENTER.</li></ol>
 * !* Executes the Format File instead of using the SET FORMAT command.

This workaround basically traps for keys like PageUp, PageDown and Escape keys, and assigns specific actions that are defined in Setkey.prg. It uses a READ CYCLE to prevent the records from scrolling abnormally.</li></ul>

<div class="moreinformation_section">

Steps to Reproduce Behavior
<ol> Start Visual FoxPro.</li> Change directory to where your format (.fmt) file is located.</li>  Type the following lines and press ENTER after each one: USE EMP_table SET FORMAT TO empform.fmt EDIT </li> Note the behavior at this point.</li></ol>

(c) Microsoft Corporation 2000, All Rights Reserved. Contributions by Reinaldo Torrales, Microsoft Corporation.

<div class="references_section">