Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Grid not displaying even after the recordsource trick
Message
From
15/09/1999 04:01:48
Cetin Basoz
Engineerica Inc.
Izmir, Turkey
 
 
To
14/09/1999 19:31:52
General information
Forum:
Visual FoxPro
Category:
Forms & Form designer
Miscellaneous
Thread ID:
00264196
Message ID:
00264833
Views:
24
>>I'm disappointed to see it's not a datasession problem
>
>me too! This is getting very irritating! Its so damn basic! I have this growing fear that I'm going to discover that its really something stupid on my part (like forgetting to have a table open - it aint that but you know what I mean!)
>
>>
>>For sum performance gain would be for you do it in one pass. IMHO I would prefer SQL if not buffered
>
>explain svp - how would this work. What sort of code are we talking about?
>
>thanks
>
>Harry


Harry,
When it's sum in grid it's generally for summing child records for a particular parent. ie: Here is our scenario (maybe a tip candidate :)
-Parent is customer and grid holds debits, credits at different dates.
-Below the grid I want to show total for debits and credits and also a balance field below them.
-There is a method that's called whenever the parent record changes (like navrefresh of wizard buttons).
-That method would be the only place where summing is done once per parent change.
-Since totals and balance would only affected by changes in credit, debit fields their valid or lostfocus code would handle the update of shown values.

Now let's go for the code :
* Summing code
luParentPK = myParent.PKField
select sum(debit), sum(credit) ;
 from myChild ;
 where myChild.KeyField = luParentPK ;
 into array aSums   && At this point records are tableupdated

with thisform
 .txtDebit.Value  = iif(type("aSums[1]") = "N", aSums[1], 0)
 .txtCredit.Value = iif(type("aSums[1]") = "N", aSums[2], 0)
endwith   && No refresh needed

* txtDebit and txtCredit controls' programmaticchange
with thisform
 .txtBalance.Value = .txtDebit.Value  - .txtCredit.Value
* I don't know how really credit, debit is processed
* it might be Credit - Debit
endwith

* txtDebit and txtCredit controls' gotfocus
* Save current value - it's contributing to total
this.tag = str(iif(isnull(this.value), 0, this.value)) && Tag is a ready storage

* txtDebit and txtCredit controls' lostfocus
with thisform.txtDebit  && txtCredit for credit
  .Value = .Value - val(this.tag) + this.Value  && Update total
endwith
This logic is just as humans do it. No need to sum all again. Subtract the old, add new. Also no fear to think record pointer movement, alias change etc. Performance would be dramatic if child had tons of records for a particular parent :) Actually I used this technique on 286s where speed was really an issue.
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
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform