Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

delphi codes for a mathematical formula

Status
Not open for further replies.

mach04

Technical User
Jun 21, 2004
237
DK
I am looking for (some) delphi codes for educational use only in mathematic, a code that describes how to build up a program for calculating a formula.
 
I am actually looking for any type of a formula that has been used to write a program. I only need it to understand how to build up a program for calculating a formula by using Delphi. The more sophisticated ones are welcome too
 
I don't understand what you mean? You don't use formulas to write programs.

any type of a formula that has been used to write a program

I only need it to understand how to build up a program for calculating a formula by using Delphi.

it would depend on what your formula is. If I want to have a user input 2 numbers and solve for:

2x/3y

then I would create a little form that has two places to enter numbers (edNumber1 and edNumber2) and a button that says calculate.

After the user enters the numbers (let's say 5 and 10) and presses the button I would have a label that appears with the answer:
something like this:

Code:
OnClick event:

var
  theanswer : float
begin
  theanswer = (2 * StrToInt(EdNumber1.Text))/(3 * StrToInt(EdNumber2.Text));//may need to use div here instead of /
  lblAnswer.Caption := floattostr(theanswer)
  lblanswer.Visible := True;
end;



Leslie
 
Thanks Leslie for your reply. I have heard there are programs that have been made by using Delphi for calculating variety of mathematical calculations. The example you gave I will try to work on (as you have noticed by now I am absolutely NEW to Delphi)it, but I was interessted in to know how how the whole such a program is entirely made by using the buttons, forms etc. etc. I beleive a full source to a program would help me to get familiar with Delphi.

Lets say a program can calculate A. To calculate this it needs several other equations. The same program can also perform calculation of B(a different calculation) which it self is based on using different equations to be solved. When the program starts you can choose either you want the program to calculate A or B. The desired program starts and you enter the data which is needed to perform that certain calculation.

I am trying to ask if anyone knows a place on the web that allows to see the full source code or a certain book which explains making such performance by delphi. A source code for some mathematical calculations writen by Delphi. I have a couple of books for Delphi but unfortunately I can't use any of the examples to help me understand the program which I want to creat.
Thanks once again
Mach
 
Well, there are Delphi components at and you can search through the Demos that come with Delphi.

For what you have described, I would create a form with two buttons:

Calculate A Calculate B

double click on buttonA and Delphi will create the OnClick event for that button.

If you want to gather user input after they press buttonA then you would need to create the form that the user should fill out (let's say edVariable1 and edVariable2) in order to perform the calculation and a button: Calculate Answer. In the OnClick event of ButtonA you would put:

frmCalculateAInput.Show

This will open the form to get the input.

In your new form, double click the Calculate Answer button, now you'll have the OnClick event for Calculate Answer. You will take the information from edVariable1 and edVariable2 (using the .Text property), and perform your calculation.

Here's a function that I have that calculates the mileage a juror has traveled:

Code:
function TfrmReviewforPayment.CalculateTotalMiles(AJuror : string; JurorMiles : integer; IsPE : boolean) : double;
var
  TripsMade : integer;
begin
//the query I'm working with
  with dmJMS.qryCalculateHours do
  begin
    //clear and replace the SQL in the query
    SQL.Clear;
    SQL.Add('SELECT * FROM JMPNEWHOUR WHERE JURNUM = ' + AJuror + ' ORDER BY SERVDAT');
    Active := True;
    //check if there are any records in the result set
    if not isempty then
    begin
      TripsMade := 0;
      {loop through the recordset and count the number of records(depending on your database you may be able to use the RecordCount property.  The database I'm using doesn't allow this property.}
      while not eof do
      begin
        //add one to TripsMade each time
        inc(TripsMade);
        Next;
      end;
      //special conditions for PublicEmployees (PE)
      if not IsPE then
        Result := JurorMiles * TripsMade
      else begin
        if JurorMiles >= 30 then
          Result := JurorMiles * TripsMade
        else
          Result := 0;
      end;
    end
    else
      Result := 0;
  end;
end;

If you are stuck on a certain thing, post back and I'll see what I can do!

leslie
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top