Board index » delphi » Sum of all Fields in a table

Sum of all Fields in a table

I'm very new at this and need help with a problem:

How can I get the sum of all the instances of a field in a table?
I need to access the value while in edit mode.  It that is not possible,

I guess I'll have to assign the value to a variable, and use the
variable.

I assume that I could use the Sum function, but I don't understand how I

define the array.
The field I want to acces is called Table1Sum.

Torstein Tysklind
torstein.tyskl...@home.se

 

Re:Sum of all Fields in a table


Some additional information regarding what you are trying to do would be
helpful.  Is this a table that has a lot of data? Are you trying to sum the
data in a grid that is attached to a table(via datasource, etc)?  Is the
table/datasource connected to components?  Do you want to sum the field for
a report?

Dave...

Quote
Torstein Tysklind wrote in message <3510405B.D9480...@home.se>...
>I'm very new at this and need help with a problem:

>How can I get the sum of all the instances of a field in a table?
>I need to access the value while in edit mode.  It that is not possible,

Re:Sum of all Fields in a table


Dave Peck skrev:

Quote
> Some additional information regarding what you are trying to do would be
> helpful.  Is this a table that has a lot of data? Are you trying to sum the
> data in a grid that is attached to a table(via datasource, etc)?  Is the
> table/datasource connected to components?  Do you want to sum the field for
> a report?

> Dave...

What I want to do is the following:

I'm writing a program to calculate working hours.  For each day I will
be writing starting and quitting hours, pauses and extra time in the evening.
On this input form I will be calculating the working hours for the day,
subtract
the 8 hours that I'm supposed to do, and I'll get out a +/- for the day. This
value I will be saving in a field.

Then I want to calculate the accumulated +/-.  To do this I'll need to sum the
+/-field.  I shall do this either for the whole table, or for all the records
up to
the current record.

I don't know if there is a Sum command that will do this for me, or if I'll
have to
have a variable, and have a loop go through all the fields and do the
calculation.
This is the solution that I have come up with while pondering over the problem
myself.

I'd be grateful for any help on how I otherwise could solve this

Torstein Tysklind

Other Threads