Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
VFP : How to get the sum of a column in a grid? Urgent!
Message
De
03/01/2000 05:17:51
Cetin Basoz
Engineerica Inc.
Izmir, Turquie
 
 
À
02/01/2000 10:23:01
Information générale
Forum:
Visual FoxPro
Catégorie:
Autre
Divers
Thread ID:
00311340
Message ID:
00311602
Vues:
11
>As subject! Please help!


Ralf,
Not always but generally grid recordsource is a child cursor and tableupdate occurs before the parent is changed. If that's the case for you too, you "only" need to do summing when parent changes. Suppose grid has to fields to be summed as "credit" and "debit". You want to show sum_credit, sum_debit and balance below the grid. Let's call controls showing them as txtCredit, txtDebit and txtBalance :
 * A custom method that's to be called when parent changes
* Since parent is changing tableupdate should have occurred
* thus SQL acts on committed data
select sum(Credit), sum(Debit) ;
  from myChild ;
  where myChild.PKLink = myParent.PK ;
  into array aSums
thisform.txtCredit.Value = nvl(iif(type("aSums[1,1]")="N",aSums[1,1],0),0)
thisform.txtDebit.Value = nvl(iif(type("aSums[1,2]")="N",aSums[1,2],0),0)

* txtCredit and txtDebit programmaticchange
thisform.txtBalance.Value = thisform.txtCredit.Value - thisform.txtDebit.Value

* txtCredit and txtDebit gotfocus
this.tag = transform(this.value) && Tag is ready storage property

* txtCredit lostfocus
thisform.txtCredit.Value = ;
  thisform.txtCredit.Value - nvl(val(this.tag),0) + nvl(this.value,0)
* Change the value with "delta" value, subtracting old, adding new

* txtDebit lostfocus
thisform.txtDebit.Value = ;
  thisform.txtDebit.Value - nvl(val(this.tag),0) + nvl(this.value,0)
This has the advantage of doing sum only once per parent rec change and no movement of rec pointer for summing. Later "sum" is only changed by values contributing to it.
Cetin
Çetin Basöz

The way to Go
Flutter - For mobile, web and desktop.
World's most advanced open source relational database.
.Net for foxheads - Blog (main)
FoxSharp - Blog (mirror)
Welcome to FoxyClasses

LinqPad - C#,VB,F#,SQL,eSQL ... scratchpad
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform