Solved

calculate table fields

Posted on 2007-04-02
4
176 Views
Last Modified: 2010-04-04
My Table1 has these values:
ID (Autoinc)
ST_POST (string)
POST_DESC (string)
PERCENT (String)  //Displays Percentage number
HOURS (String) // I manually enter number of hours)
To do some calculus in the grid i added 2 more calculated  fields:
CALC1 (Currency,To get this value i use on calculate fields of the Table1):
Table1CALC1.Value := Query2SALLARY.Value / Table2HOURS_MONTH.Value;
It workz ok...
CALC2 (Currency ...)
How can I get CALC2 to give me results of this formula (if PERCENT ='50'   ! !!!):
CALC2 = a * (b * 50/100) ;
Value 'a' is CALC1
Value 'b' is HOURS
Should I make PERCENT and HOURS into integere type fields as they are allways numbers?
0
Comment
Question by:srbenavrbe
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
4 Comments
 
LVL 21

Expert Comment

by:ziolko
ID: 18838957
why don't you write SQL query that will return values already calculated?

ziolko.
0
 
LVL 17

Accepted Solution

by:
TheRealLoki earned 250 total points
ID: 18839484
If you want to keep it as strings, then you could do something like this :-

procedure TForm1.Table1CalcFields(DataSet: TDataSet);
var
  calc1, calc2: double; // storing in temp variables so you can easily work with them
  percent_: double;
  hours_: integer;
begin
  calc1 := Query2SALARY.Value / Table2HOURS_MONTH.Value;
  Table1CALC1.Value := calc1;
// now calculate CALC2
  // if using strings
  percent_ := 0; // default
  hours_ := 0; // default
  if (not Table1PERCENT.IsNull) then
    percent_ := StrToIntDef(Table1PERCENT.AsString, 0); // default to 0 if not set
  if (not Table1HOURS.IsNull) then
    hours_ := StrToIntDef(Table1HOURS.AsString, 0); // default to 0 if not set
  calc2 := calc1 * (hours_ * (percent_/100)) ;
  Table1CALC2.Value := calc2;
end;
0
 
LVL 1

Expert Comment

by:Computer101
ID: 21156534
Forced accept.

Computer101
EE Admin
0

Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
select query - oracle 16 103
Breakpoint doesn't stop in my variable 3 48
Firemonkey Listview item popup menu ? 1 72
Using MMsystem To change audio input 1 38
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial

734 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question