Você está na página 1de 21

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: Number of data records: Date of last update: Memo file block size: Code Page: Field Field Name 1 PRODUCTID 2 SUPPLIERID 3 PRODNAME 4 ENGNAME 5 QTYSIZE 6 UNITPRICE 7 UNITCOST 8 QTYINSTOCK 9 MINQTYTOST 10 DISCONTINU 11 LASTORDER 12 INFO

C:\TEMP\PRODUCTS\PRODUCTS.DBF 77 02/27/98 64 1252 Type Width Dec Character 6 Character 6 Character 40 Character 50 Character 20 Numeric 8 2 Numeric 8 2 Numeric 12 3 Numeric 12 3 Logical 1 Date 8 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 : select the text box control select Caption in the Properties Box

enter the desired caption in the edit box [shaded pink for identification and marked with red arrow]

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. Original Value New Value Productid: Product ID # Supplierid: Supplier ID # Productname: Description Engname: Name Qtysize: Quantity Size Unitprice: Unit Price Unicost: Unit Cost Qtyinstock: In Stock Minqtytost: Minimum Discontinu: Discontinued Lastorder: Last Ordered Info: ----------- Prompt removed 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 select the form - touch anywhere on the form except a control or button select BackColor in the Properties Box enter the RGB [Red,Green,Blue] code in the edit window or press chart. (See Below) for a color

at homas.
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 select the text box control(s) select FontSize in the Properties Box enter the desired size in the edit box or select from the edit box pull down menu (See Below)

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 select the text box control(s) select FontBold in the Properties Box select True from the edit box pull down menu or double click FontBold selection to change (See Below)

In order to make the text box control unbold select the text box control(s) select FontBold in the Properties Box select False from the edit box pull down menu or double click FontBold selection to change

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 select the text box control(s) select ForeColor in the Properties Box enter the RGB [Red,Green,Blue] code in the edit window or press chart. (See Below) for a 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 select the text box control(s) select ForeColor in the Properties Box enter the RGB [Red,Green,Blue] code in the edit window or press chart. (See Below) for a color

Changing The Font Size Of The Edit Box Control

In order to change the edit box control font size select the edit box control(s) select FontSize in the Properties Box enter the desired size in the edit box or select from the edit box pull down menu (See Below)

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 select the edit box control(s) select FontBold in the Properties Box select True from the edit box pull down menu or double click FontBold selection to change (See Below)

In order to make the edit box control unbold select the edit box control(s) select FontBold in the Properties Box select False from the edit box pull down menu or double click FontBold selection to change

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 select the edit box control(s) select ForeColor in the Properties Box enter the RGB [Red,Green,Blue] code in the edit window or press chart. (See Below) for a color

In order to change the font background color

select the edit box control(s) select BackColor in the Properties Box enter the RGB [Red,Green,Blue] code in the edit window or press chart. for a 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 select the edit box control(s) select ForeColor in the Properties Box enter the RGB [Red,Green,Blue] code in the edit window or press chart. (See Below) for a color

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 select the form - touch anywhere on the form except a control or button select Caption in the Properties Box enter the desired title - Be sure to include the author(s) and the table (See Below)

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

Changing The Caption Of The Next Push Button Control

In order to change the Next push button control caption : select the push button control select Caption in the Properties Box enter the caption, Next, in the edit box (See Below)

Linking The Push Button Control With Procedure Next


In order to make the Next push button call/execute procedure Next select the Next push button control double click the Valid Event in the Properties Box enter Do Next - close the edit window - save

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.

Skip a couple of blank lines between your procedures to make them easier to find, edit, etc.
The code for all buttons shall be added to a file called Code.PRG. Do It! 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 : select the push button control select Caption in the Properties Box enter the caption, Previous, in the edit box

Linking The Previous Push Button Control With Procedure Previous


In order to make the Previous push button call/execute procedure Previous select the Previous push button control double click the Valid Event in the Properties Box enter Do Previous - close the edit window - save

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 Delete Do Next Return <-- Beginning of the Procedure Delete <-- Delete the current record - Don't forget to indent! <-- Move the read/write pointer to the next undeleted record <-- 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 : select the push button control select Caption in the Properties Box enter the caption, Delete, in the edit box

Linking The Previous Push Button Control With Procedure Delete


In order to make the Delete push button call/execute procedure Delete select the Delete push button control double click the Valid Event in the Properties Box enter Do Delete - close the edit window - save

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

Changing The Caption Of The Add Push Button Control


In order to change the Add push button control caption : select the push button control select Caption in the Properties Box enter the caption, Add, in the edit box

Linking The Previous Push Button Control With Procedure Add


In order to make the Add push button call/execute procedure Add select the Add push button control double click the Valid Event in the Properties Box enter Do Add - close the edit window - save

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 : select the push button control select Caption in the Properties Box enter the caption, Exit, in the edit box

Linking The Previous Push Button Control With Procedure Exit


In order to make the Exit push button call/execute procedure Exit select the Exit push button control double click the Valid Event in the Properties Box enter Do Exit - close the edit window - save

Sample Button Layouts

Database Form Guidelines

Você também pode gostar