Sie sind auf Seite 1von 10

Tutorial: FoxPro C - Database Program Code & Window Control

Dr. Thomas E. Hicks Computer Science Department Trinity University


1. Sample Structure 2. Help 3. Modify Structure 4. Wait 5. Modify Command 6. To Create Program File ListState.PRG 7. Do 8. Program File Command Suggestions 9. Define Window 10. Activate Window 11. Deactivate Window 12. Release Window 13. Define Window (Advanced - Fonts & Titles) 14. Program DisplayNamePhone 15. Set AutoSave On/Off 16. Set Print On/Off 17. Set Status bar On/Off 18. Set Bell On/Off 19. Set escape On/Off 20. Display Status 21. List Status 22. Possible Exam/Quiz Questions - FoxPro #C
All of the following FoxPro Commands Can Be Entered Into The Command Window (these commands are not case sensitive)

Sample Structure
Let us assume the Clients.DBF for the following illustrations. The structure/layout is as follows: NAME .........Character ADDRESS ......Character CITY .........Character STATE ........Character ZIP ..........Character PHONE ........Character BALD .........Logical AGE. .........Numeric NOTES ........Memo 16 16 12 2 5 8 1 3 4

Help
Help FoxProCommand <-- enter the on-line FoxPro help system and display the information about the specified command. Help Use <-- enter the on-line help system and show the information about the command use. Help List <-- enter the on-line help system and show the information about the command list .

Modify Structure
Modify Structure<-- change the layout/structure of the database open in the current work area. Fields may be deleted with the delete button. Fields may be added with the insert button. Fields sizes and datatypes may be changed. Field positions may be switched. All of this can be done quite easily and quickly. All database records will be automatically adjusted. (See Below)

Wait
Wait Message Window Wait Window Message <-- creates a small system type window in the top right corner of the screen. This window contains the message . All processing is delayed until the user strikes a key or depresses the mouse button. When the key/mouse is depressed window disappears and processing continues. Wait "Record Not Found" Window<-- creates a small system type window in the top right corner of the screen. This window contains the message "Record Not Found". All processing is delayed until the user strikes a key or depresses the mouse button. Wait Window "Hit Any Key To Continue" Timeout 5 <-- creates a small system type window in the top right corner of the screen. This window contains the message "Hit Any Key

To Continue". All processing is delayed until the user strikes a key or depresses the mouse button or 5 seconds (which ever occurs first). (See Below)

Holding down the Ctrl or the Shift key will temporarily hide the wait window. (Try It!)

Modify Command
All of the FoxPro commands learned thus far may be entered into the Command Window. In order to avoid re-typing collections of commands, all of our FoxPro commands may also be placed into a program file and executed with a single command. The command illustrated in this section shall be used to group and order our commands. Modify Command FileName <-- create/modify a program file and enter the program editor. The program file will have a .PRG extension. Program files contain one or more FoxPro commands. The menu-driven program editor has the standard cut, paste, copy, etc. text processing options. Modify Command ListState<-- edits a file, called ListState, and enters the program editor. If the file ListState.PRG does not exit, it iis created and then opened to edit. If the file ListState.PRG does exit, it is opened to edit. (See Below)

File->Save <-- to save file from inside the editor File->Close <-- to exit editor ESC <-- to exit editor

To Create Program File ListState.PRG - Sample A


The purpose of the ListState program file is to (1) clear the screen, (2) display the Name, Phone, and State fields of all records on the monitor display with a pause, (3) activate a wait window which displays the string "Display of Names is Complete - Hit Any Key To Continue" and (4) clears the screen after the user responds to the Wait Window in step 3. All of these commands could be entered into the Command Window. Let us assume that this is a sequence of commands which the user wishes to do on a regular basis. 1] Modify Command ListState.PRG <-- creates/opens a file, called ListState, and enters the program editor; the extension is optional. 2] Type the following

Clear Display All Name, Phone, State Wait "Display of Names is Complete - Hit Any Key To Continue" Window Clear

3] File->Save [pull down the File Menu and select Save to save program file ListState.PRG] 4] ESC [ hit the ESC key to close editor]

Do
Do FileName <-- execute the commands in a program file. Do ListState <-- execute program file ListState.PRG (not case sensitive) Do liststate.PRG <-- execute program file ListState.PRG . (all program files must have a .PRG extension; including the extension is optional) Do LISTSTATE.PRG<-- execute program file ListState.PRG .

Holding down the Ctrl or the Shift key will temporarily hide the wait window. (Try It!)

Program File Command Suggestions 1. Use upper/lower case to increase readability


List FirstName, LastName, SocSecNo For State = "TX" AND City = "San Antonio" is easier to read than list firstname, lastname, socsecno for state = "TX" AND City = "San Antonio"

1. Use blank lines to separate logic chunks 2. Indent logic chunks and loops 3. Document program code Define Window
Define Window WindowName From X1, Y1 To X2, Y2 Define Window OutputWin From 5,10 To 10,50 <-- by default, it uses the font and size of the parent window. Uses 10 point FoxFont by default. Window OutWin is defined approximately 5 rows and 40 characters to a row; the border is included in the size. When activated the window will look like the following:

Display Memory <-- displays local variables, FoxPro system variables, window definitions, menu definitions, and pop-up window definitions. The default number of user variables that may exit at any one time is 1024; this may be increased to as many as 65,000. (Only the window variables are displayed below). Window Definitions
Name From To Size

OUTPUTWIN 8.188,62.500
1 Window Defined

368

5.000,10.000 bytes

Define Window WindowName At X1, Y1 Size X2, Y2 Define Window OutputWin At 5,10 Size 5,40 <-- by default, it uses the font and size of the parent window. Uses 10 point FoxFont by default. Window OutWin is defined approximately 5 rows and 40 characters to a row; the border is included in the size.

Activate Window
Activate Window WindowName <-- open window and make it current user-defined the window must be previously defined. Activate Window OutputWin <-- open window Output as the current window.As long as OutputWin is the current window, all List, Display, etc. will appear in that window. Activate Window OutputWin, InputWin, GetStateWin ... <-- open more than one window in one command; the last window in a series becomes the current window. Input is the current window. Activate Window all <-- open all defined windows in one command; the last window in a series becomes the current window.

Activate Window OutputWin Noshow <-- direct output to a window without display.

Deactivate Window
Deactivate Window WindowName <-- close the activated window the previously defined window must be activated. Deactivate Window OutputWin <-- close the window Output. Deactivate Window OutputWin, InputWin, DisplayWin... <-- close more than one window in one command Deactivate Window all <-- closes all active windows.

Release Window
Release Window WindowName <-- close the activated window and delete the window definition. Release Window OutputWin <-- close the activated window and delete the window definition for window Output. Release Window OutputWin, InputWin, ... <-- close and delete more than one window in one command Release Window<-- close and delete the current window.

Define Window (Advanced - Fonts & Titles) Define Window OutputWin at 1, 2 Size 8, 40 Font 'ROMAN' , 16 <-- Roman 16 Font (See Below)

Define Window OutputWin at 1, 2 Size 8, 40 Font 'ROMAN' , 16 Style 'BI' <-- Bold Italic Font

Style Key Bold = B Italic = I Normal = N Outline = O Shadow = S Strikeout = Transparent = T Underline = U

Define Window OutputWin at 1, 2 Size 4, 60 Font 'ROMAN', 16 ; Style 'BI' Title 'Output Window' <-- Title Window

Define Window OutputWin at 1, 2 Size 4, 60 font 'ROMAN', 12 ; Style 'OIU' Title 'Output Window' <-- Title Window

Program NamePhone
The purpose of the program DisplayNamePhone is to (1) set the default drive and directory to folder Demo on drive C, (2) open the Clients.DBF table, (3) clear the screen, (4) define an output window, called ClientWin - include an appropriate title, (5) bring ClientWin to the desktop as the active window, (6) display the Name, Phone, and State fields of all records in ClientWin with a pause, (6) activate a wait window which displays the string "Hit Any Key To

Continue" and (7) takes down the command window.. All of these commands could be entered into the Command Window. Let us assume that this is a sequence of commands which the user wishes to do on a regular basis.
Set Default to c:\Demo Use Clients Clear Define Window ClientWin at 1, 2 size 8, 40 ; font 'ROMAN', 16 style 'BI' Title 'Client State Listing' Activate Window ClientWin Display All Name, Phone, State Wait "Done - Hit Any Key To Continue" Deactivate Window ClientWin

Do DisplayNamePhone<-- execute program file NamePhone.PRG . Do DisplayNamePhone.PRG<-- execute program file NamePhone.PRG .

Set AutoSave On/off


Set AutoSave Off<-- information is written to disk every five minutes. This is more hardware and disk efficient, but one could loose five minutes worth of work in the event of a power blackout. (default) Set AutoSave On <-- information is written to disk immediately. Each little piece is written to disk as entered. Since the software does not wait until it has several changes to update, there is more wear and tear on the hardware drives when this option is set.

Set Print On/Off


Set Print On <-- all list and display commands direct an additional copy of the ASCII information to the printer. Set Print Off <-- a copy of the information will not be directed to the printer. (default)

Set Status Bar On/Off


Set Status Bar On <-- turn on the status bar at the foot of the screen (default) Set Status Bar Off <-- turn on the status bar at the foot of the screen.

Set Bell On/Off


Set Bell On <-- the bell sounds during editing when invalid data is entered and when the end of a field is reached. (default) Set Bell On <-- the edit bell is turned off. The bell pitch and duration can be set; check the help system or the manual if desirable.

Set Escape On/Off


Set Escape On <-- the escape key interrupts the processing. (default) Set Escape Off <-- the escape key does not interrupt processing.

Display Status
Display Status <-- display FoxPro environment information. Databases open, indexes, relations, the procedure file in use, the default drive, the current work area, etc. All of the set option variables, such as bell, escape, print, near, status bar, autosave, etc. will be displayed. As is the case with all display options, the output will pause when the screen is full. The following is output from display status:
Processor is Pentium

Currently Selected Table: Select area: 1, Table in Use: C:\CLIENT\CLIENT.DBF CLIENT Code page: 1252 Structural CDX file: C:\CLIENT\CLIENT.CDX Index tag: STATE Machine Key: ALLTRIM(UPPER(STATE)) Index tag: NAME Machine Key: ALLTRIM(UPPER(NAME)) Memo file: C:\CLIENT\CLIENT.FPT Lock(s): Exclusive USE
File search path:

Alias:

Collate: Collate:

Default directory: C:\CLIENT Print file/device: Work area Margin Decimals Memowidth Typeahead Blocksize Reprocess Refresh DDE Timeout DDE Safety
Code page: 1252

= 1 = 0 = 2 = 50 = 20 = 64 = 0 = 0,5 SECONDS = 2000 = on

Collating sequence: Machine Compiler code page: 1252 Date format: American Macro Hot Key = UDF parameters are passed by: Textmerge Options Delimiters: Left = Show
Alternate - off

VALUE << Right = >>

Fullpath

- on

ANSI Asserts Bell Blink Brstatus Carry Century

off off off on off off off

Heading Help Intensity Lock Logerrors Mouse Multilocks

on on on off on on off

Clear Color Compatible Confirm Console Cursor Deleted Device Echo Escape Exact Exclusive Fields Fixed

on on off off on on on scrn off on off on off off

Near Null Optimize Print Readborder Safety Space Status Bar Sysmenus Talk Textmerge Title Unique

- on - off - on - off - off - on - on - on - on - on - off - off - off

List Status
List Status <-- display FoxPro environment information. Databases open, indexes, relations, the procedure file in use, the default drive, the current work area, etc. All of the set option variables, such as bell, escape, print, near, status bar, autosave, etc. will be displayed. As is the case with all display options, the output will not pause when the screen is full. List Status To File Status<-- displays the FoxPro environment information on the screen and creates a text copy in file Status.TXT in the current directory. (no pause) List Status To Print<-- print the FoxPro environment information. (no pause)

Das könnte Ihnen auch gefallen