Cardbox > Forums > Macros and Programming > "calculating in macro's"
calculating in macro's
Posted By | Post |
---|---|
Yvette Waard | 27-Oct-2008 15:05 I need to calculate in en between different records. In Cardbox 3.0 there is no calculator to use. |
Charles Welling | 27-Oct-2008 15:49 You can add the contents of a field in a selection by right-clicking the field and then choose "Total". Cardbox will go through your selection, add up all the numbers in that particular field and then give you the total. More sophisticated calculations may need a macro written by yourself, which is very simple in VBscript. The Internet (try www.w3schools.com for instance) will give you an unlimited number of examples. |
Mary Doyle | 28-Oct-2008 23:31 Yvette, Here is a sample macro that you might be able to adapt to your requirements: Assumption: TotalCount = 0 ' TotalCount is a variable to store the sum as you move through each record, which is set at 0 to start, not always necessary Set recs = Records n = recs.Count For i = 1 to n ' i = each record from 1 to the last record in the set, as the macro loops through the set Set rec = recs(i) ' i.e. Eact active record in the loop TotalCount = 0 +TotalCount+rec.Fields("ia") ' invoice item amount - using 0 (zero) at the beginning tells Vbscript to treat the statement as numbers Next ' i.e. moves on to next record in the set If n>0 Then If this doesn't make sense check the Cardbox macros and programming manual or many of the VbScript sites on the Internet. Hope this helps. Mary |