I need to calculate in en between different records. In Cardbox 3.0 there is no calculator to use.
In Cardbox 2.0 there was a macro called 'total' that we used for calculating our total stock which was read from different records, each record is a seperate lotnumber of our production. The user himself could type which field needed to be totalized.
How can I write this macro in Cardbox 3.0?
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.
Here is a sample macro that you might be able to adapt to your requirements:
You have a field "ia" Invoice Amount
You have a field "into" Invoice Total
Everything after the single quote (') is a comment and is not part of the macro
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
' as + can also be used for concatenation (see Vbscript on Internet for explanation)
Next ' i.e. moves on to next record in the set
If n>0 Then
Set rec=recs(n) ' recs(n) is the last record in the set
rec.Fields("into")=TotalCount ' Field invoice total ' This will store the result in the invoice total field
If this doesn't make sense check the Cardbox macros and programming manual or many of the VbScript sites on the Internet.