












Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Community
Ask the community for help and clear up your study doubts
Discover the best universities in your country according to Docsity users
Free resources
Download our free guides on studying techniques, anxiety management strategies, and thesis advice from Docsity tutors
Instructions on creating a menu and defining procedures for a Visual FoxPro database application. It covers the use of wizards, screen menus, and command-line prompts to create windows, define options, and display data. The document also includes instructions for handling user input and navigating through records.
What you will learn
Typology: Summaries
1 / 20
This page cannot be seen from the preview
Don't miss anything!
Proceedings of the International Conference on Theory and Applications of Mathematics and Informatics - ICTAMI 2004, Thessaloniki, Greece
by Valentin Casavela
Abstract: Visual studio 6.0, witch comprises Visual FoxPro6.0, must be installed.In order to build a screen menu, either we entirely create that, or we call the Wizard from Run menu , but *.scx and *.sct files will be built up. So, the file s tudents. scx was built up by us and belongs to screen menu designing , but this can not be used in a program and must be transformed in a *.spr file, which belongs to that design too. Our screen menu was designed with the Wizard hereby: From RUN\Witzard from FoxProW menu , the Screen option was chosen. A window was opening , where the database could be chosen and we might input values. With NEXT option we may select fields from the database, in which the values were inputting. In order to talk about a Database, the terms FIELD and RECORD must be understood. Keywords : data base, field, record, prompt, bar, popup
Data base
Database may be seen as a table, where a field means all the values or strings in a column and a record means the same, but in a row, as in the example bellow:
field1 field2 field
Name birthday Tell record Brand Johns 04/03/1981 0256- record Osborn Monica 01/09/1980 0257-
For a new Database, in the Command Window , write: CREATE < file_name >
In the new window, introduce the name, the type and the field length, as in figure:
If the example above is used, then complete this: Name Type width (nr. of chars ) name Character 20 data Date 8 tel Character 11 Press Enter and a window with the question : Input data record now? is opening. Answer NO and Close it. The new created file is students.dbf. We will choose earlier another way for inputting dates: form. But, for modifying this database, type in Command Window: Close all and from File , open in Microsoft Visual Studio\Vfp the new created file, students.dbf. In Command Window :USE "c:\ program files\microsoft visual studio\vfp98\stu-dents.dbf" EXCLUSIVE appears. Enter and type in Command Window : modi stru. Enter and the figure above is shown again. You may modify it and, with YES, save the changes.
….from View select Proprieties; so you may change the aspect of the window STUDENTS. For instance, click on ‘ Name ’ and in Proprieties select FontSize and type 12 upside. After, select FontBold and select True upside, as follows:
Close it and operate in Command Window. Type do FORM students.scx (or select Program\Do and a Do window appears, in which select Form in Files of type. Open STUDENTS.SCX, a new window, STUDENTS is opening and here you may input dates. Click on Add and type dates from the first table of this paragraph: Bend Johns…i.e. After every record click Save and Add. Click Exit when you finished. This database is called “students” and it should be used in the application which we will design in the next step. To modify this, type in Command Window: DO FORM students.scx or select in Program\Do\All files: Students ( above STUDENTS .CDX). Besides that, it’ll be another database, “ medium ” ( medium.dbf , created in the same way ), with structure: name type width decimals Name Char 20 Statistics Numeric 3 0 Modeling Numeric 3 0 C_sharp Numeric 3 0 C_plusplus Numeric 3 0
Database Numeric 3 0 Lisp Numeric 3 0 Medium Numeric 5 2
To use this database, a Visual FoxPro program must be written. Further, it is shown this program, which holds a situation of several students’ names, exams results and mediums.A program is opened by writing in the Command Window:
close all
MODI COMM < program name>
and is running with DO
MODI COMM application
Then, an edit window is opening. You may type in the following instructions, or you may copy the entire program application.prg. For that, from CD , in aplicatii\ DATABASE-VS-FOXPRO-20 click right on application.prg and open it with WordPad. Press Ctrl-A for Select All and Ctrl-C for copy. Now, return in edit Window and press Ctrl-V for past. You may see the program. But, to write your own application, type the next statements, without comments (*…):
set talk off ** stop printing on screen the commands results clear * clean screen _@ 5,10,9,65 box ''_ * it draws a rectangle with characters ‘ * ‘, at coordinates 5,10 *(left-top corner) and 9,65 (bottom-right corner), where the first value is for row and *the second is for column.
*define popup rat ** rat is a character string, given by us to this submenu define bar 1 of rat prompt 'Students' define bar 2 of rat prompt 'Results' define bar 3 of rat prompt ‘Results Selection’
define popup rest define bar 1 of rest prompt 'Failed to Exams’ define bar 2 of rest prompt 'To Which Exam ?' define bar 3 of rest prompt ‘First’
define popup ex define bar 1 of ex prompt 'Windows' define bar 2 of ex prompt 'Fox Pro' The option
*on pad opt1 of meniu activate popup rez on pad opt2 of meniu activate popup rat ** we launch the submenu rat pad opt3 of meniu activate popup ex on pad opt4 of meniu activate popup search on bar 3 of rat activate popup rest Besides this, the command ON SELECT would be employed in order to choose a bare option or a submenu, going to the execution of anything else then the activation of a submenu or a menu. So, procedures from the same program, other programs from disk, or forms i.e., may be called and run.
on select bar 2 of rat do afis * call and run the ‘afis’ procedure on select bar 2 of rez do intr * call and run the ‘intr’ procedure on selection bar 2 of ex return * call and run the ‘return’ function, to exit the program *and to return to Visual FoxPro on selection bar 1 of ex quit * call and run the ‘return’ function to exit the program *and to return to Windows on selection bar 1 of rez do form students.scx *call and run the form “studenti.scx,” *previously created. The passway is: define pad opt1 of meniu prompt 'Overview' *… on pad opt1 of meniu activate popup rez… define bar 1 of rez prompt 'Students' on selection bar 1 of rat do afisst * call and run the “afisst” procedure.
on selection bar 1 of rest do rest * call and run the “ rest” procedure on selection bar 1 of search do search * call and run the “search” procedure on select bar 2 of rest do searching * call and run the “searching” procedure on select bar 3 of rest do goods * call and run the “goods” procedure The deactivation of a menu bare is made with: DEACTIVATE MENU
Next, we will define the procedures just called above.After we selected the “ Students ” option, from the submenu “ Overview ”, the form (screen ) students.scx run and appears and we may select, from the same submenu, the “ Results ” option and then the procedure “ intr ”, which is shown bellow, is launched. The passway is… define pad opt1 of meniu prompt 'Overview' …. on pad opt1 of meniu activate popup rez … define bar 2 of rez prompt 'Results' …. on select bar 2 of rez do intr
procedure intr * Procedure defining is made with PROCEDURE <name *procedure>. @ 4,0 clear to 32,200 * clean the screen between points 4,0 and 32, The clauses SHARED and EXCLUSIVE are employed in networking, and NOUPDATE refers a READ ONLY database. For more details, in Command Window type help Use and Enter.
use medium in 1 * open the “ medium database ”, created above, in work area
r='Y' * initialize r variable with character Y @ 4,18 say ' ----------------------------------------------- ' *display a string of chars ‘-’, *beginning with position 4, @ 24,18 say '-----------------------------------------------' *display a string of chars ‘-’, *beginning with position 24,
@20,20 say 'medium=' ??medium else appe blank * appends a void record. The new is a new name. go bottom * positions the cursor on the last record, which just was appended. @7,20 say "This is a new name!! Please enter marks !!" replace name with new @ 8,20 say 'Statistics : ' get statistics * introduces in “Statistics” field, from
_j=22_* The first column number for displaying exam results. It’ll be incremented _@i,1 say name_* display name field @i,j say 'statistics=' ??statistics * display statistics field For displaying , we may type a field name prefixed by? or ??, the difference being that? causes passing to the next row. _?? ' ' @i,j+15 say 'modeling=' ??modeling ?? ' ' @i,j+30 say 'database=' ??database ?? ' ' @i,j+44 say 'C#=' ??C_sharp ?? ' ' @i,j+52 say 'C++=' ??c_plusplus ?? ' ' @i,j+62 say 'lisp=' ??lisp ??' ' @i,j+71 say 'medium=' ??medium_ last column or field _i=i+1 @i,0,i,110 box _ display a line to separate records i=i+1 pass to next row or record _if i>=32_ does a page finish? _p=replicate(' ',12)_ Yes.. Specify the character expression that is replicated, that is * *space.
12 specifies the number of times the character expression is replicated. _@31,7 say 'Do you want to see the next page? y and Enter/ n and Enter' get p read_ ask user _if upper(p)='Y'_* go to next page *@3,0 clear to 32, 200 ** …but, first, clean the window
else go bottom @3,0 clear to 32, endif endif
skip *passes to the next record enddo * closes the do cycle close all * closes the database Afterwards , only students fallen to exams and to which exams, will be dis-played. For that, we use database named medium in procedure rest, activated on the way: define pad opt2 of meniu prompt 'Display Printing', ….. on pad opt2 of meniu activate popup rat, …. define bar 3 of rat prompt 'Results Selection’ … …. on bar 3 of rat activate popup rest …. define bar 1 of rest prompt ‘Failed to exam' … on selection bar 1 of rest do rest. and we may see what student has marks less then 5 and to which discipline.
procedure rest @ 4,0 clear to 32,200 * cleans screen use medium * open the “medium” database. This case, if you eventually open another atabase, this medium database will be closed. i=5 * variable takes value 7 do while (!EOF()) * while we are not touching the end of the database, … j=30 * variable “j” takes value 30 _if statistics <5_ if statistics mark is less then 5,… _@ i+1,2 say name_* display name, _@ i+1,j+1 say 'Statistics'_* display _Statistics j=j+10_* and increase column with 10, to repeat displaying for other failed exam _endif if modeling< @ i+1,2 say name_* if a student failed more exams, we keep the same row,… _@ i+1,j+1 say 'Modeling'_* but jump some columns _j=j+ endif if C_sharp< @ i+1,2 say name_* likewise @ i+1,j+1 say 'C#'
_j=j+ endif if database< @ i+1,2 say name @ i+1,j+1 say 'DataBase' j=j+ endif if C_plusplus< @ i+1,2 say name @ i+1,j+1 say 'C++' j=j+ endif if lisp< @ i+1,2 say name @ i+1,j+1 say 'Lisp' j=j+ endif i=i+1_* pass to the next line for the next record (name)
*if i>=32 ** Ask the user for next page displaying.Likewise the other procedures above. p=replicate(' ',12) @35,7 say 'Do you want to see the next page? y and Enter/ n and Enter' get p read if upper(p)='Y' @3,0 clear to 36, 200 i= else go bottom @3,0 clear to 36, endif endif
skip * pass to the next record and repeat conditions enddo *closes “do while”cycle close all * closes database, previously opened. If somebody wants to search in database for information about a certain stuent, he will have to input student name in a variable and run through
@ 11,10 say 'Statistics : ' * display text string “ Statistics” : @ 11,28 say statistics * display contents of statistics field @ 12,10 say 'Modeling : ' @ 12,28 say modeling @ 13,10 say 'DataBase : ' @ 13,28 say data_base @ 14,10 say 'C# : ' @ 14,28 say C_sharp @ 15,10 say 'Lisp : ' @ 15,28 say lisp @ 16,10 say 'C++ : ' @ 16,28 say C_plusplus @ 18,15 say 'Medium : ' @ 18,28 say medium else @ 12,10 say 'The marks for that student where not input' * ..if the student *wasn’t found neither in medium data base, display the text: The marks… endif close the “if conditional instruction body”. _enddo_ search finished close all Suppose we want to follow up the exam situation for a group of students, especially for students follen to a certain exam. As we have seen in the former presenting procedure, in a variable we must input the exam name and then we shell see which student follen that exam. The passway is… define pad opt2 of meniu prompt 'Display Printing’ …. on pad opt2 of meniu activate popup rat… define bar 3 of rat prompt 'Results Selection'…on bar 3 of rat activate popup rest …. define bar 2 of rest prompt 'To Which Exam ?' …. on select bar 2 of rest do searching.
*procedure searching @ 4,0 clear to 32, use medium ** open the database named medium *ex=replicate(' ',12) ** the ex variable is 12 characters long @ 10,10 say 'Type the exam name: ' get ex * Input in ex variable the value typed from *the keyboard. read i=
if upper(alltrim(ex’))= upper('statistics') * if “statistics” was typed, then look for a *student, which has a value less then 5, in statistics field. do while (!EOF()) *that is, run through the entire students database if Statistics<5 * if a student has the statistics mark less then 5, then his name will be displayed. _@ i+1,10 say name i=i+ do nextpage_ if the table of names exceeds the current window, call the bellow * nextpage procedure endif skip enddo endif
We proceed similarly for every exam, to which the student was possibly present. _if upper(alltrim(ex))= upper('modeling') do while (!EOF()) if modeling< @ i+1,10 say name i=i+ do nextpage_* if the table of names exceeds the current window, call the bellow
_if upper(alltrim(ex))= upper('database') do while (!EOF()) if Data_base< @ i+1,10 say name i=i+ do nextpage_* if the table of names exceeds the current window, call the bellow * nextpage procedure
endif skip enddo
close all A database sorting leads to a new database, called
The last procedure, called many times above, is nextpage .This was discussed when it was used as a simple program sequence, in afisst procedure or in others.
procedure nextpage if i>= p=replicate(' ',12) @31,7 say 'Do you want to see the next page? y and Enter/ n and Enter' get p read if upper(p)='Y'
@11,0 clear to 32, 200 i= else go bottom @ 11,0 clear to 32, endif endif After writing all those instructions in the program editing window, save and close this window, with key combination CTRL+W. After that, write, in the command window, “DO Application”. If all was correctly written, the program is launching, but if it wasn’t, an error message is displaying. There may be exist fields in a database, in which the values must not be input, because those either are co-pied or result from a calculation. Again NEXT and we select one of the 3 predefined display types, again NEXT and input the students’ names. Chose Modify Screen with DesignTtool and select FINISH. After few moments, the window studenti.scx is ope-ning and we may see how our screen looks like and we would modify the design. After the modifies were finished, from Program submenu (FoxProW) select GENERATE option, which will build the studenti.spr file and, automatically, studenti.spx file too. That file is launched in execution, when click on Students in Input submenu. In the same moment with the student.scx file building, the studenti.sct file was built up too.
References:
Author: Valentin Casavela - University of Petrosani, Romania