Tutorial: FoxPro D - Database Procedures & Screen Forms

Dr. Thomas E. Hicks
Computer Science Department
Trinity University


  1. Main Program
  2. Decide The Size For The New Screen
  3. Creating Your First Screen - Quick Form
  4. Changing The Caption Of The Text Box Control
  5. Changing Form Color
  6. Changing The Font Size Of  The Text Box Control
  7. Changing The Font Boldness Of The Text Box Control
  8. Changing The Font Colors Of  The Text Box Control
  9. Sizing The Text Box Control To Fit
  10. Changing The Font Size Of  The Edit Box Control
  11. Changing The Font Boldness Of  The Edit Box Control
  12. Changing The Font Colors Of  The Edit Box Control
  13. Sizing The Edit Box Control To Fit
  14. Screen Layout
  15. Changing Screen Title
  16. Next Button Code
  17. Changing The Caption Of  The Next Push Button Control
  18. Linking The Push Button Control With Procedure Next
  19. Starting the Main Program
  20. Previous Button Code
  21. Changing The Caption Of  The Previous Push Button Control
  22. Linking The Previous Push Button Control With Procedure Previous
  23. Delete Button Code
  24. Changing The Caption Of  The Delete Push Button Control
  25. Linking The Previous Push Button Control With Procedure Delete
  26. Add Button Code
  27. Changing The Caption Of  The Add Push Button Control
  28. Linking The Previous Push Button Control With Procedure Add
  29. Exit  Button Code
  30. Changing The Caption Of  The Exit  Push Button Control
  31. Linking The Previous Push Button Control With Procedure Exit
  32. Sample Button Layouts
  33. Possible Exam/Quiz Questions - FoxPro D


All of the following FoxPro Commands Can Be Entered Into The Command Window
(these commands are not case sensitive

Download and decompress the data file for this example and design your own FoxPro application as you walk through the tutorial.

 Products1.zip      Installing WinZip Tutorial     Using WinZip Tutorial

Create a folder, called Products, in the Temp folder of hard drive C; your directory  C:\Temp\Products should look like the following:

Windows 95/NT Tutorial

Structure for table:                    C:\TEMP\PRODUCTS\PRODUCTS.DBF
Number of data records:       77
Date of last update:          02/27/98
Memo file block size:         64
 Code Page:                   1252
         Field     Field Name   Type          Width                 Dec
             1     PRODUCTID    Character        6
             2     SUPPLIERID   Character        6
             3     PRODNAME     Character       40
             4     ENGNAME      Character       50
             5     QTYSIZE      Character       20
             6     UNITPRICE    Numeric          8                   2
             7     UNITCOST     Numeric          8                   2
             8     QTYINSTOCK   Numeric         12                   3
             9     MINQTYTOST   Numeric         12                   3
            10     DISCONTINU   Logical          1
            11     LASTORDER    Date             8
            12     INFO         Memo

 


Main Program

In order to avoid typing a lot of stuff in the command line each time we wish to start our application, let us design a good Main.PRG  (Do It!)

Modify Command Main

Set Default To C:\Temp\Products    <-- establish the default drive/folder
Use Client                                     <-- commented open database Client.DBF
Set Deleted On                              <-- turn on the deleted filter
Set Bell Off                                    <-- turn off the bell
Set Near On                                   <-- allow searching to find a near match
Set Procedure To Code                   <-- associate the button code file for the current screen application
Clear                                             <-- clear the console screen
Do Form Products                                <-- run the Products screen form

 


Decide The Size For The New Screen
Tools-->Options    [Using the mouse, hold down the tools menu and select Options
                                   Select the Forms Tab. Change the Maximum design area to 640x480.
                                  Change the Horizontal and Vertical spacing to 6 pixels each.

 Using the mouse, select the Set As Default button. (Do It!)

Until this configuration is changed, all new screens will be designed for low resolution 640 x 480 monitors with snap to grid set to 6 pixels.

 


Creating Your First Screen - Quick Form

Create Screen Products <-- Launches the screen designer to create a screen called Products.SCX.

Using the mouse, hold down the form  menu and select QuickForm as illustrated above. A form builder will now emerge. As is the case with the other FoxPro Menus, the Form Control menu may be in the menubar at the top, may be loose on the screen (as illustrated above) or may be closed. If closed, the toolbar may be opened by holding down the View Menu and selecting Forms Control Tool Bar.

Used to add the selected field from the Products database table to the Selected Fields list used to construct controls for the new form.
  Used to add all fields from the Products database table to the Selected Fields list used to construct controls for the new form.
   Used to remove the selected field from the Selected Fields list.
  Used to remove all fields from the Selected Fields list.

Let us select all fields. (See Below)

Select the Tab form builder. (See Below)

 Select the Embossed Style and Select the OK button. (See Below)

FoxPro has now given its best shot at an automated form for the Products database table.

 


Changing The Caption Of The Text Box Control

The text box control is used to present text information, such as field prompts, on the user designed screen forms. When using the quick form,  the field names have been selected as prompts;  field names  are often make very poor prompts; examples of poor prompts would be evident in the captions on the screen above : Productid, Unitprice, Lastorder, etc. The objective is to make each and every caption so explicit, that all can use the database screen without the need for clarification of data.

Each caption/prompt is a text box control object whose properties may be altered. Let us change the caption of Productid to Product ID #. First use the mouse and select the text box control; when selected, a box will appear around the text box.

Second let us activate the Properties Box by holding down the right mouse button on the object and selecting Properties as demonstrated above. The Properties Box is illustrated below. This step may be omitted when the properties box is already on the desktop.

In order to change the text box control caption :

It will be in the edit box of the Properties Box that many of the screen objects are changed. In the screen below, most of the captions have been changed. Some of the new caption  information seems to be missing in the screen below; relax, since the text box control field retains its original size, some of the data is simply hidden at the moment.  Shortly, I will show you how to resize the text box control field so that all of each caption might be displayed.

This button, from the form controls tool bar, can be used to add a new text box control to a screen.

 


Changing Form Color

In order to make the text box control bold

athomas.

Custom colors may be configured as well. (See Below)



 


Changing The Font Size Of  The Text Box Control

In order to change the text box control font size

You may use your mouse and select multiple text box controls to change at one time; hold down the shift key to continue selections.

 


Changing The Font Boldness Of The Text Box Control

In order to make the text box control bold

 In order to make the text box control unbold

You may use your mouse and select multiple text box controls to change at one time; hold down the shift key to continue selections.
 

Changing The Font Colors Of  The Text Box Control

In order to change the font color

 You may use your mouse and select multiple text box controls to change at one time; hold down the shift key to continue selections.

 


Sizing The Text Box Control To Fit

In order to change the text box control to the correct size for the caption

Changing The Font Size Of The Edit Box Control

In order to change the edit box control font size


You may use your mouse and select multiple text box controls to change at one time; hold down the shift key to continue selections.

This button, from the form controls tool bar, can be used to add a new edit box control to a screen.

 


Changing The Font Boldness Of The Edit Box Control

In order to make the edit box control bold

 In order to make the edit box control unbold

You may use your mouse and select multiple text box controls to change at one time; hold down the shift key to continue selections.
 

Changing The Font Colors Of The Edit Box Control

In order to change the font color

In order to change the font background color

 You may use your mouse and select multiple text box controls to change at one time; hold down the shift key to continue selections.
 

Sizing The Edit Box Control To Fit

In order to change the text box control to the correct size for the caption

Screen Layout

The mouse can be used to re-position objects on the screen in a drag and drop process.

I. Put the most important information at the top of  the screen.

II. Most screens should contain 1 - 3 columns

III. Avoid wild color combinations.

IV. Avoid too many different size fonts.

V. Try to avoid large gaps on the page.

VI. Align the prompt captions and the edit fields. The captions below need help. Select the left row of captions with the mouse on the screen below. Pull down the Format Menu and Select Align and select Align Right Sides.

The results of the right alignment may be seen below. This will also be done with the left column.

FoxPro also makes it very easy to achieve horizontal alignment in each row. Select the left row of captions with the mouse on the screen below.

Pull down the Format Menu and Select Align and select Align Right Sides.

With proper alignment, our screen now looks like the following:



Changing Screen Title

In order to change the screen title from Form1



Next Button Code

The purpose of the Next button is to move the cursor to the next record. This button, from the form controls tool bar, can be used to add a new push button control to a screen. The Next Button should be on the far right-hand side of the screen.

The code for all buttons shall be added to a file called Code.PRG. Do It!

modify command Code

Procedure Next                         <-- Beginning of the Procedure Next
    Skip 1                                  <-- Skip a record - Don't forget to indent!
    If EOF() Then                        <-- Start of the  If Then Else Decision Statement
         Goto Top                         <-- When you hit the End Of File Then Goto the top of the file
    EndIf                                    <-- Start of the  If Then Else Decision Statement
    _screen.activeform.refresh     <-- Refresh the screen form
Return                                     <-- Return control to place that called Next
EndProc                                   <-- End of Procedure - Optional Statement
 


Changing The Caption Of  The Next Push Button Control

In order to change the Next push button control caption :


 

Linking The Push Button Control With Procedure Next


 In order to make the Next push button call/execute procedure Next

Starting the Main Program


Do Main    <-- To start the Products screen when in the default directory.
Do C:\Temp\ProductsMain <-- To start the Products screen from any directory.

Double click on My Computer. Double click on Temp. Double click on Products.
Double click on Main.PRG <-- To start the Products screen from Windows.

 


Previous Button Code

The purpose of the Previous button is to move the cursor to the previous record. The Previous Button should be on the far left-hand side of the screen.

The code for all buttons shall be added to a file called Code.PRG. Do It! Skip a couple of blank lines between your procedures to make them easier to find, edit, etc.

modify command Code

Procedure Previous                   <-- Beginning of the Procedure Previous
    Skip -1                                <-- Skip back one record - Don't forget to indent!
    If BOF() Then                       <-- Start of the  If Then Else Decision Statement
         Goto Bottom                   <-- When you hit the Beginning Of File Then Goto the bottom of the file
    EndIf                                   <-- Start of the  If Then Else Decision Statement
    _screen.activeform.refresh     <-- Refresh the screen form
Return                                      <-- Return control to place that called Previous
EndProc                                   <-- End of Procedure - Optional Statement
 


Changing The Caption Of  The Previous Push Button Control


In order to change the Previous push button control caption :

Linking The Previous Push Button Control With Procedure Previous


 In order to make the Previous push button call/execute procedure Previous

Delete Button Code

The purpose of the Delete button is to delete the current record. The Delete Button may be placed anywhere, that is organize effectively,  the screen.

The code for all buttons shall be added to a file called Code.PRG. Do It! Skip a couple of blank lines between your procedures to make them easier to find, edit, etc.

modify command Code

Procedure Delete               <-- Beginning of the Procedure Delete
    Delete                           <-- Delete the current record - Don't forget to indent!
    Do Next                        <-- Move the read/write pointer to the next undeleted record
Return                               <-- Return control to place that called Delete
EndProc                            <-- End of Procedure - Optional Statement
 


Changing The Caption Of  The Delete Push Button Control


In order to change the Delete push button control caption :

Linking The Previous Push Button Control With Procedure Delete


 In order to make the Delete push button call/execute procedure Delete

Add Button Code

The purpose of the Add button is to move the cursor to the previous record. The Add Button may be placed anywhere, that is organize effectively,  the screen.

The code for all buttons shall be added to a file called Code.PRG. Do It! Skip a couple of blank lines between your procedures to make them easier to find, edit, etc.

modify command Code

Procedure Add                         <-- Beginning of the Procedure Add
    Append Blank                      <-- Append  new blank record at eof - move read/write pointer to that record
    _screen.activeform.refresh     <-- Refresh the screen form
Return                                     <-- Return control to place that called Add
EndProc                                  <-- End of Procedure - Optional Statement
 


Changing The Caption Of  The Add Push Button Control


In order to change the Add push button control caption :

Linking The Previous Push Button Control With Procedure Add


 In order to make the Add push button call/execute procedure Add

Exit  Button Code
The purpose of the Exit button is to exit the screen form. The Exit Button may be placed anywhere, that is organize effectively,  the screen.

The code for all buttons shall be added to a file called Code.PRG. Do It! Skip a couple of blank lines between your procedures to make them easier to find, edit, etc.

modify command Code

Procedure Exit                          <-- Beginning of the Procedure Exit
    _screen.activeform.release     <-- Refresh the screen form
Return                                      <-- Return control to place that called Exit
EndProc                                   <-- End of Procedure - Optional Statement
 


Changing The Caption Of  The Exit  Push Button Control


In order to change the Exit push button control caption :

Linking The Previous Push Button Control With Procedure Exit


 In order to make the Exit push button call/execute procedure Exit

Sample Button Layouts


Database Form Guidelines


 


May be accessed through URL: http://www.cs.trinity.edu/~thicks
May also be accessed through URL: http://carme.cs.trinity.edu
This Document May Not Be Printed or Reproduced Without Written Permission.
 2003 Copyright : Dr. Thomas E. Hicks
Permission granted : Professional Educators & College Students may print one copy of this page!

Dr. Thomas E. Hicks

Computer Science Department    
Trinity University

"Dr. Web"