6 |
The LA Fox Developer Newsletter
December 199T
Visual
Time &
Effort
(Con’t
from page
5)
2.
I then set up the data environment with the two tables and
linked them via the position number field.
3.
Next I dragged the relevant parent fields onto the form and
gave them labels.
4.
I then formed a grid in the lower part of the form and named
it”grdEffort”; the COLUMNCOUNT property is 2,
RECORDSOURCE property of the grid is TIMEEFFI, the
RECORDSOURCETYPE property is 1-Alias, and the VIEW
property is 0 BROWSE BROWSE.
See illustration to see what my form looks like.
II. Control Buttons
1.
I next needed to add navigation buttons. From the Classes
Icon on the Toolbar, I “Added”
d:\vfox\samples\controls\buttons.vcx.
This gave me some sample foxpro button objects to add to
my form. I chose the vcr icon and placing this sample on
form “Time & Effort” gave me the Top, Bottom, Previous and
Next buttons with no coding on my part.
2.
I then added the following Buttons: Search, Browse, Print
and Done. To the Click code of these buttons I added
normal code. As an example for the Browse button I added
code to display the parent table but not allow users to
modify this data:
browse nomodify
thisform.refresh()
3.
I then added two buttons for the Grid; Add and Delete. To
the Click methods of these two buttons I added the follow-
ing code:
Add Code:
select timeeffi
append blank
replace posnumb with position.posnum
thisform.grdEffort.fundorg.txtfundorg.set
thlsform.grdEffort.Refresh()
Delete code:
select timeeffi
delete next I
Ill.
Percent Total field
I added a TEXTBOX on the parent form named
nTotalPercent and gave it a label as well.
2.
In the form designer, I went up to Form on the toolbar an
added a NEW PROPERTY: PercentTotal.
3.
I next went up to Form and added a NEW METHOD:
calcpercent
4.
In the properties window of the Form frmTime, the bottom
property is calcpercent. Double clicking on this method
brought up the click code for calcPercent and here I added
the following code:
para positlonumber
*
this procedure sums all percentages for a given position #
SELE timeeffi
IF SEEK(positionumber)
SUM pctfund for posltionumber=posnumb;
TO nPercent
ELSE
nPercent
=
0
ENDIF
SELE position
RETURN npercent
5.
Now I had the procedure to calculate percent totals and
needed to run this method whenever
a) you started the project
b) a new employee (parent) record was displayed
c) an addition, change, or deletion was made in the grid
percents
6.
I found that the three PROPERTIES that could do this were
the INIT property when starting the project, REFRESH
property for a new record and the
change.
INIT Code of Form
CLOS ALL
CLEAR
THISFORMSET.NPERCENTTOTALthi5f0rm5et.calcpercents(posnum)
REFRESH Code of Form
THlSFORMSET.NPERcENuoTAL=thisformseLcaIcpercents(p~num)
AfterRowColChange Code of Grid:
LPARAMETERS nCollndex
m rec
=
rec n 00
mposnumbposnumb
SUM pctfund for mposnumb=posnumb TO
thlsform.PercentTotal
go mrec
thisform.nTotalPercent.Refresh()
IV.
When run, I found that indeed, the nPercentTotal
field did contain a running total of my percent field from the child
table.
(Ed. Note: Mike Merino works for Denver Public Health. He
can be reached at MMerino@dhha.org. The Time & Effort
project is his second Visual Foxpro program. He and his wife
Jonna are enjoying their new 9 month old daughter Molile, whose
keyboard technique is still rather random.]
Page 6
|
6 |