Data Base Application in Visual Foxpro: by Valentin Casavela
Data Base Application in Visual Foxpro: by Valentin Casavela
Data Base Application in Visual Foxpro: by Valentin Casavela
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 students. 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:
In the new window, introduce the name, the type and the field length, as
in figure:
70
Valentin Casavela - Data Base application in Visual FoxPro
But, let’s come back to form. Our screen menu was designed with the
Wizard hereby: from FoxPro menu select Tools\Witzard\Form and a
window, Wizard Selection appears. Select Form Wizard and press O.K. In
the window Form Wizard\ Databases and tables select Students and in
Available fields select ‘ >>’ (all). In Selected fields appear all students’
fields. Click on Next. In the next window, Step2, select Style: Embossed and
Button Type: Text Buttons . Many choices above and which follow are
default, but you may try others.
Click Next.: Step3. In Available fields or index tag, we order names
by alphabetic: Ascending and, with Add> select all fields for Selected files,
by repeated action. In other cases, you may omit some fields. In Step4- Finish:
Type a title for your form write Students, select Save form and modify in
the Form Designer and click on Finish. A window Save as appears and click
on Save. The new file Sudents.scx may be found in Program Files\Microsoft
Visual Studio\Vfp98\. Verify that !
The follow window is opening and….
72
Valentin Casavela - Data Base application in Visual FoxPro
….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:
73
Valentin Casavela - Data Base application in Visual FoxPro
Database Numeric 3 0
Lisp Numeric 3 0
Medium Numeric 5 2
close all
74
Valentin Casavela - Data Base application in Visual FoxPro
@ 23,10 say
'******************************************************** '
@ 37,10 say ' VALENTIN CASAVELA ‘
@ 10,25 to 20,56 PANEL * it draws a rectangle, with left top corner
coordinates: *10,25 and right bottom coordinates : 20,56.
@ 12,29 say '- Western University -'
@ 13,33 say ‘“Vasile Goldis"’ * the Informatics Faculty
identifications are *displayed inside the…
@ 16,30 say ’Informatics Faculty' * …rectangle
@ 17,30 say 'Tel.: 0257-214505 '
define menu meniu
“bare” option will be named < bare1_option > and will belong to the
menu bare <menu_ name>, and the text will be <expC1>, displayed at a
certain position, with the specification AT <line>,< column>. To set a certain
order for bare options, we use the clauses BEFORE or AFTER. For more
details, in Command Window type help DEFINE PAD and Enter.
define popup ex
define bar 1 of ex prompt 'Windows'
define bar 2 of ex prompt 'Fox Pro'
The option <pad name> of the menu bare <menu name1> activates the
sub-menu <popup name>, or the menu <menu name2>.
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.
76
Valentin Casavela - Data Base application in Visual FoxPro
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 <menu name1>
[, <menu name2> ...] | ALL
deactivate menu meniu
Our menu will look like:
Overview Display Printing Search Exit
Students Students Students Windows
Results Results FoxPro
Faild to exams All
Exam
First
use medium in 1 * open the “medium database”, created above, in work area
1.
r='Y' * initialize r variable with character Y
@ 4,18 say '-----------------------------------------------' *display a string of chars
‘-’, *beginning with position 4,18
@ 24,18 say '-----------------------------------------------' *display a string of chars
‘-’, *beginning with position 24,18
77
Valentin Casavela - Data Base application in Visual FoxPro
do while upper(r)='Y' *”upper” changes the character ‘r’ in upper case. So,
*while r=‘y’, or r = ’Y’, the program repeats the next instructions, till enddo.
Other-*wise, it does’nt. ‘r’ is the character inputed somewhere bellow, but
above the *ENDDO instruction, the ‘Y’ or ‘y’ inputs being the condition for
*“while” cycle. The *upper instruction leaves ‘r’ unchanged if r=‘Y’.
@3,0 clear to 32, 200
new=replicate(' ',26)
@ 6,20 say 'Name :' get new* introduces in “new” field the string inputted
from the *keyboard.No more then 26 digits. Press Enter.
read
locate for upper(alltrim(name))=upper(alltrim(new)) )*turn all characters,
either *upper- case or lower- case, in upper-case. While the end of the
database isn’t touched…
if found()* …test if in “name” field there is the same value as in “new”
variable, for *medium database only! For avoiding the situations as “John
” <> “John”, use *alltrim to clear spaces ( ex. alltrim (“John “)=“John”).
Also exist ltrim – clean all *left spaces. rtrim – clean right spaces.
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.
i=5* Again, the first row number for displaying names and exam results
else
go bottom*If ‘No’, positions on the last appended record
@3,0 clear to 32,200*clean the window
endif
endif
skip *causes passing to the next database
enddo
@3,0 clear to 32,200*clean the window
close all
else
go bottom
@3,0 clear to 32,200
endif
endif
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<5
@ 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+10
endif
if C_sharp<5
@ i+1,2 say name* likewise
@ i+1,j+1 say 'C#'
82
Valentin Casavela - Data Base application in Visual FoxPro
j=j+6
endif
if database<5
@ i+1,2 say name
@ i+1,j+1 say 'DataBase'
j=j+11
endif
if C_plusplus<5
@ i+1,2 say name
@ i+1,j+1 say 'C++'
j=j+6
endif
if lisp<5
@ i+1,2 say name
@ i+1,j+1 say 'Lisp'
j=j+1
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=5
else
go bottom
@3,0 clear to 36,200
endif
endif
the entire database till a record, which has in name field a value equal with that
of his variable. So, the student will be found. Then the information will be
displayed. To set the passway, we wrote above: define pad opt4 of meniu
prompt 'Searching'…. on pad opt4 of meniu activate popup search …define
bar 1 of search prompt 'Student',…..on selection bar 1 of search do search
procedure search
@ 4,0 clear to 32,200 * clear screen
name =replicate(' ',30) * initialize the “name” variable with a string of 30
characters.
@ 6,10 say 'Input name : ' get name’* in “name” variable input the string
typed from *the keyboard.
use students in 1 * open the database “students” in the 1-st work zone.
use medium in 2 * open the database “medium ” in the 2-nd work zone
sele 1 * select database, opened in the 1-st work zone.
*to search for a certain record , FoxProW has the instruction LOCATE FOR.
*locate for alltrim(name)=alltrim(name1)
locate for upper(alltrim(name))=upper(alltrim(num) )*turn all characters,
either upper- *case or lower- case, in upper-case. While the end of the
database isn’t touched…
if found()* test if in “name” field there is the same value as in “num” variable,
for *students database only! For avoiding the situations as “John ” <>
“John”, use *alltrim to clear spaces ( ex. alltrim (“John “)=“John”). Also
exist ltrim – clean all *left spaces. rtrim – clean right spaces.
@ 9,10 say 'Birthday : ' * display the text string “Birthday”
@ 9,28 say birthday * display Birthday
@ 10 ,10 say 'Tel : ' * display the text string Tel :
@ 10,28 say tel * display the field contents “ tel”
else
@ 8,10 say 'This student dates were not introduced'* fail in searching
endif
sele 2 * select database opened in 2-nd work zone.
locate for upper(alltrim(name))=upper(alltrim(num))*Even we did’nt find
num in *students database (selected from Display Printing/Students-only for
verifying num), *we search for that in medium data base, (selected from
Display Printing/Results- for *verifying num).
*Maybe here, that student name was found. To find that, FOUND()
logical *instruction is used, which returns true if it could find, or false if it
couldn’t.
if found() * if found..
84
Valentin Casavela - Data Base application in Visual FoxPro
procedure searching
@ 4,0 clear to 32,200
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=10
85
Valentin Casavela - Data Base application in Visual FoxPro
We proceed similarly for every exam, to which the student was possibly
present.
if upper(alltrim(ex))= upper('modeling')
do while (!EOF())
if modeling<5
@ i+1,10 say name
i=i+1
do nextpage*if the table of names exceeds the current window, call the bellow
*nextpage procedure
endif
skip
enddo
endif
if upper(alltrim(ex))= upper('database')
do while (!EOF())
if Data_base<5
@ i+1,10 say name
i=i+1
do nextpage*if the table of names exceeds the current window, call the
bellow *nextpage procedure
endif
skip
enddo
86
Valentin Casavela - Data Base application in Visual FoxPro
endif
if upper(alltrim(ex))= upper('c#')
do while (!EOF())
if C_sharp<5
@ i+1,10 say name
i=i+1
do nextpage*if the table of names exceeds the current window, call the bellow
*nextpage procedure
endif
skip
enddo
endif
if upper(alltrim(ex))= upper('c++')
do while (!EOF())
if C_plusplus<5
@ i+1,10 say name
i=i+1
do nextpage*if the table of names exceeds the current window, call the bellow
*nextpage procedure
endif
skip
enddo
endif
if upper(alltrim(ex) )= upper('lisp')
do while (!EOF())
If Lisp<5
@ i+1,10 say name
i=i+1
do nextpage*if the table of names exceeds the current window, call the bellow
*nextpage procedure
endif
skip
enddo
endif
87
Valentin Casavela - Data Base application in Visual FoxPro
close all
A database sorting leads to a new database, called <file>, sorted by
field <field1> in ascening or in descending order. This sorting has however a
problem: every time when we select the option “First”, that sorting will be
made and therefore a file, with the same name, will be created. So, every time a
message will be displayed, a message which tells us that this file exists and
asks if we would write over that. Every time choose YES.
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 3 of rest prompt 'First'… on select bar 3 of rest do goods
procedure goods
@ 4,0 clear to 24,79 * clear screen
use medium in 1 * open the database „medium“
sort to med on medium /D *sort descending database after the field “medium”
and the *sorted database “med” will result .
use med in 2 * open the new database in work zone 2
sele 2 * select work zone 2
k=7
For a variable taking values from <expN1> to <expN2>, with the “
STEP <expN3>”, the <statement>.instruction group is executed.
for i=1 to 5
@ k+i,5 say name
@ k+i,30 say medium
skip
endfor
close all
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>=28
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'
88
Valentin Casavela - Data Base application in Visual FoxPro
References:
Author:
Valentin Casavela - University of Petrosani, Romania
89