Link to home
Start Free TrialLog in
Avatar of TeChNiCh
TeChNiCh

asked on

Table calculating

Well lets see... i made a table Paradox 7.

when i push button1 then i want the program to calculate
all Columns 3 and label1.caption will be the answer

ex: i got 20 rows in the table and all row has column 3
and i want the proggie to check 1st column 3 and add that with 2nd column 3 and then add it with 3rd column and label1.caption will show the right answer
Avatar of CrazyOne
CrazyOne
Flag of United States of America image

Run a query like this

'SELECT Sum(Feild1) + Sum(Feild2) + Sum(Feild3) AS TotalOfAll
FROM Table1';
Now grap the total like this

Lable1.Caption := Query1.FieldByName('TotalOfAll').AsString;
Here it is all together

with Query1 do begin
     with SQL do begin
          Clear;
          Add('SELECT Sum(Feild1) + Sum(Feild2) + Sum(Feild3) AS TotalOfAll');
          Add('FROM Table1');
     end;
     Open;
     Lable1.Caption := FieldByName('TotalOfAll').AsString;
     Close;
end;
Of course with all three fields in queston the Data Type needs to be of a numeric type for this to work.
Avatar of Hamlet081299
Hamlet081299

I think the intention was to just get the total of column 3...

with TQuery.Create(nil) do
try
  DatabaseName := '???';
  SQL := 'select sum(column3) from table1';
  Open;
  Label1.Text := Fields[0].AsString;
finally
  Free;
end;
>>>i want the program to calculate all Columns 3

Well now I am a bit confused hopefully TeChNiCh will clarify it for us. I thought it was a typo and meant to read as 3 Columns. :>)

How have you been doing Hamlet? I am glad to be working a thread with you.
Avatar of TeChNiCh

ASKER

Hamlet understood correct
Or i would like all Column 3 to be added not just on 1 row but on all rows
I also get an error when i change the table... Database allready in use or some
How can i do so if Column3Enterpressed then autoupdate the label1 and also create a new row in the table.... thats the only problem at the moment
I think we need more backgorund on what you are doing...

It sounds like you have a grid that is displaying the values?

Is this grid connected to a TTable or a TQuery?

Are the values meant to be editable for all columns or just column 3?

The more details you give the better.

(p.s. Hi CrazyOne.  I'm doin' well.  Looking forward to a big trip in just over a week.  I won't be going near a keyboard for almost two weeks!  Yay!)
I got a grid connected to Table and Column 3 has
number value.

im doing like:

Column1          |    Column2     | Column3
Income from           Description   Cash


im very bad at explaining sorry for that :P
ASKER CERTIFIED SOLUTION
Avatar of SpideyMod
SpideyMod

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial