Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

I have a grid on my form that has p

Status
Not open for further replies.

DanNorris2000

Technical User
Nov 10, 2000
186
US
I have a grid on my form that has percentages in one of the columns, Is there a way to place a text box on the same form which would total those percentage?
 
Hi!

Yes, but you require to do some code in some places.

Make custom method on form that will calculate sum in your cursor using SUM command and show it in the control. Call that method in form Init (to calculate it when form first time opens) and in the valid event of the control in the appropriate column of grid (to refresh it). You can use even InteractiveChange event for refreshing just as user types.

THere are some problems, however, when user tries to scroll grid horizontally. It is not easy to move such box properly under grid. If your grid scrollable horizontally, let me know here, I will write some more tips for that.





Vlad Grynchyshyn
vgryn@softserve.lviv.ua
The professional level of programmer could be determined by level of stupidity of his/her bugs
 
Where you at now Vlad? John Durbin
john@johndurbin.com
MCP Visual FoxPro
ICQ VFP ActiveList #73897253
 
Thanks , sounds a bit outside the scope of my skills, but I will do my homework
 
Created a form method and entered the following:

local InRecno
local InSelect
InSelect=select()
InRecno=recno (participants)
select participants
calculate;
sum(participants.share)to ThisForm.txtPercentTotal.value
goto InRecno in participants
select InSelect

Text box on my form has the following in the Valid Procedure

ThisForm.TotalPercent()

Am I getting close?
 
Yes what you wrote should work fine. Below is how my method would look, but the result is the same. It's all just syntax LOL

cCurrentTable = ALIAS() &&remember current alias
nSum = 0

SELECT participants
nRec = RECNO()
CALCULATE SUM(share) TO nSum
GOTO nRec &&restore record pointer in participants
thisform.textbox.value = nSum &&assign value

IF !EMPTY(cCurrentTable) THEN &&restore alias
SELECT &cCurrentTable
ENDIF

thisform.refresh


-Pete
 
Can definately understand your code better, but neither seem to work for me. My textbox remains blank. Could it be because my text box is on a pageframe? or the fact that I am suming child fields in a one to many relationship?
 
Hmmm try summing child fields...

CALCULATE SUM(fieldYouWantToTotal) ;
FOR ParentTableRelationValue = ChildTableRelatedFieldName

or something like that

Have you tested your CALCULATE command in the command window? IMO it is a lot easier to play with there then in the form's method. Get it working in the command window first then port it to your method.

Good Luck!
-Pete
 
Sorry to keep this thread rolling

Would I place this code in the init of the DE or somewhere in the grid of the page Im in? What procedure would it go under?

cCurrentTable=Alias()
nSum=0
select participants
nRec=Recno()
calculate sum(share) to nSum for; pool.ctrpoolno=participants.ctrpoolno
Goto nRec
thisform.pageframe1.page1.totpercent.value=nsum
IF !empty(cCurrentTable) Then
Select &cCurrentTable
Endif
Thisform.refresh

Unable to get it to work in command window either
 
Assuming nSum is the controlSource for a read only textboxt on your form. And assuming that the user can edit the grid and thereby change/update the value of nSum.

Place your calculate function in the grid's afterRowColumnChange event. You may have already buolt some traps for refreshing the entire form after some significant change. If so placing it in the form's refresh event would be fine too.

BTW: This SQL function CALCULATE can drag your performance down on a large table and repeated hits. You might consider only calling this function when the form is initialized, then change the nSum value in the grid's textbox validation event.
-Pete
 
your assumption is correct , text box is read only and grid is editable. Im only dealing with about 5 hundred records so performance shouldnt be too bad. I placed code in theafterRowColumnChange event but I get "record out of range" error when run.
I have reindexed
 
I again reindexed and lost the error but only 0.00 shows up in my textbox while I see amounts in my grid flash by as I roll thru the recs
 
Ok nothing shows as I roll thru the records. But, if I click on the column, then yes, It does show my total. I would like to see the value change as I go thru the records without editing.
 
Your using two tables... filter participants by current value of pool record. Is it possible that pool's record pointer is getting moved? In any event try adding in a line and changing the CALC a bit...

cCurrentTable=Alias()
nSum=0
vCtrPoolNo = pool.ctrpoolno
select participants
nRec=Recno()
calculate sum(share) to nSum for;
vCtrPoolNo = participants.ctrpoolno



-Pete
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top