Board index » delphi » Problems with programming a new Math tool

Problems with programming a new Math tool

Hello there.

I am programming a new math tool useing Delphi 3.0, and now I am haveing a
few problems.

1. I have created a form where it is calculated how much the sum is of
differents objects like a circel, a square and a triangle. I am useing the
code

...
procedure TArealCirkel.Button1Click(Sender: TObject);

var
FirstNumber, SecondNumber: Integer;

begin
FirstNumber := StrToInt(Edit1.Text);
SecondNumber := StrToInt(Edit2.Text);
Edit3.Text := IntToStr((FirstNumber * FirstNumber) * (22 div 7));
end;
...

And now it is that I can't find out, how to use decimal numbers.

(22 div 7) should be something like 3.14, but instead it is 3 and then I
can't make very exact calculation.

2. I also need to know how I can execute a exe-file on the harddisk, for an
example notepad.exe, if it is posible to use parameters like notepad.exe
c:\texts\readme.txt

3. I have created a webpage where there will be on-line help and updates.
How can I create a menuItem or button which opens a browser with the
webpage. The url for the webpage will be something like
www.schoolapps.ml.org, I don't know right now.

4. I know how to open a new form by pressing a button or menuItem, but how
can I chance so that it opens a new form and then closeing the one before.
I don't know to close the form before, so there can be 2-4 forms open at the
same time and thats a problem.
----------------------------------------

If you have any suggestions please post it to me.

If you want to mail me then use b...@get2net.dk

Thank you for reading, and I hope you can help me.

 

Re:Problems with programming a new Math tool


Quote
>(22 div 7) should be something like 3.14, but instead it is 3 and then I
>can't make very exact calculation.

The result of  22 div 7  is an integer, a number with no decimal numbers.
You should use 22/7 to get a number with decimal numbers, like a real-type.

Re:Problems with programming a new Math tool


Yes use / for normal division but remember that the result will be a
real and you can therefore not use it as an integer in functions like
inttostr(x) and you can not use it as input in a drawing function
like.. elleipse(x,y,a,b) you will in first case need to convert to
string with flowattostr(x) and in later example you would need to use
either trunc or round.
Trunc makes 3,8 into 3 and rund makes it into 4

Re:Problems with programming a new Math tool


Quote
In article <6ujh2t$ce...@news.IAEhv.nl>, "Oostra" <goos...@IAEhv.nl> writes:
>The result of  22 div 7  is an integer, a number with no decimal numbers.
>You should use 22/7 to get a number with decimal numbers, like a real-type.

Just use Pi - gives you 3.1415926 etc etc etc.

Or if you must have integers use 355/113 - near enough for 7 significant
figures.

Alan LLoyd
alangll...@aol.com

Re:Problems with programming a new Math tool


Quote
>1. I have created a form where it is calculated how much the sum is of
>differents objects like a circel, a square and a triangle. I am useing the
>code

>...
>procedure TArealCirkel.Button1Click(Sender: TObject);

>var
>FirstNumber, SecondNumber: Integer;

>begin
>FirstNumber := StrToInt(Edit1.Text);
>SecondNumber := StrToInt(Edit2.Text);
>Edit3.Text := IntToStr((FirstNumber * FirstNumber) * (22 div 7));
>end;
>...

Try this translation:

procedure TArealCirkel.Button1Click(Sender: TObject);
var
   FirstNumber, SecondNumber: Double;
begin
   FirstNumber := StrToFloat(Edit1.Text);
   SecondNumber := StrToFloat(Edit2.Text);
   Edit3.Text := FloatToStr(FirstNumber * FirstNumber * PI);
end;

This will allow the user to input a floating point number as the radius of
the circle, and will return a precice value for the area of the circle.  I'm
just not sure what "SecondNumber" is the value of.  If you want to round
your answer in Edit3.Text to two or three decimal places, here's how.

Edit3.Text := FloatToStr(round(FirstNumber * FirstNumber * PI * 1000) /
1000);  // use 100 to round to 2 places, 10000 for 4 places, etc.

Quote
>4. I know how to open a new form by pressing a button or menuItem, but how
>can I chance so that it opens a new form and then closeing the one before.
>I don't know to close the form before, so there can be 2-4 forms open at
the
>same time and thats a problem.

You can't close the calling form, but you can make it invisible
(Form2.Visible := FALSE)

Oracle
<oracle-z...@bmts.com>
Remove the "-zzz-" if you wish to reply by mail.

Re:Problems with programming a new Math tool


Another problem is the fact that STRTOINT() converts a string to an
INTEGER. Try STRTOFLOAT, or something similar...

Another thing is that you are confusing Pascal operators:

+, -, * work as they should

but...

there are 3 operators to use for division:

DIV returns ONLY the INTEGER part of the divided number
MOD returns the Modulous (the remainder after division)
/   does a proper divide

therefore:

22 DIV 7 = 3
22 MOD 7 = 1 (because 21/7 = 3, and 22 - 21 = 1!!)
22/7 = 3.1

There are a number of ways to work with the multiple form situation. The
most obvious (and probably the best programatically), is to close all
forms (except the main form), free them from memory (also do not
autocreate), and re-create tehm when needed. This will, of course,
depend on the forms and what you are trying to do with them

David Russell

Quote
> "AKSEL J?RGENSEN" wrote:

> > Hello there.

> > I am programming a new math tool useing Delphi 3.0, and now I am haveing a
> > few problems.

> > 1. I have created a form where it is calculated how much the sum is of
> > differents objects like a circel, a square and a triangle. I am useing the
> > code

> > ...
> > procedure TArealCirkel.Button1Click(Sender: TObject);

> > var
> > FirstNumber, SecondNumber: Integer;

> > begin
> > FirstNumber := StrToInt(Edit1.Text);
> > SecondNumber := StrToInt(Edit2.Text);
> > Edit3.Text := IntToStr((FirstNumber * FirstNumber) * (22 div 7));
> > end;
> > ...

> > And now it is that I can't find out, how to use decimal numbers.

> > (22 div 7) should be something like 3.14, but instead it is 3 and then I
> > can't make very exact calculation.

> > 2. I also need to know how I can execute a exe-file on the harddisk, for an
> > example notepad.exe, if it is posible to use parameters like notepad.exe
> > c:\texts\readme.txt

> > 3. I have created a webpage where there will be on-line help and updates.
> > How can I create a menuItem or button which opens a browser with the
> > webpage. The url for the webpage will be something like
> > www.schoolapps.ml.org, I don't know right now.

> > 4. I know how to open a new form by pressing a button or menuItem, but how
> > can I chance so that it opens a new form and then closeing the one before.
> > I don't know to close the form before, so there can be 2-4 forms open at the
> > same time and thats a problem.
> > ----------------------------------------

> > If you have any suggestions please post it to me.

> > If you want to mail me then use b...@get2net.dk

> > Thank you for reading, and I hope you can help me.

Re:Problems with programming a new Math tool


the IntToStr function converts an INTEGER to a String. To to use decimals you
have to use real numbers.
good luck
Quote
"AKSEL J?RGENSEN" wrote:
> Hello there.

> I am programming a new math tool useing Delphi 3.0, and now I am haveing a
> few problems.

> 1. I have created a form where it is calculated how much the sum is of
> differents objects like a circel, a square and a triangle. I am useing the
> code

> ...
> procedure TArealCirkel.Button1Click(Sender: TObject);

> var
> FirstNumber, SecondNumber: Integer;

> begin
> FirstNumber := StrToInt(Edit1.Text);
> SecondNumber := StrToInt(Edit2.Text);
> Edit3.Text := IntToStr((FirstNumber * FirstNumber) * (22 div 7));
> end;
> ...

> And now it is that I can't find out, how to use decimal numbers.

> (22 div 7) should be something like 3.14, but instead it is 3 and then I
> can't make very exact calculation.

> 2. I also need to know how I can execute a exe-file on the harddisk, for an
> example notepad.exe, if it is posible to use parameters like notepad.exe
> c:\texts\readme.txt

> 3. I have created a webpage where there will be on-line help and updates.
> How can I create a menuItem or button which opens a browser with the
> webpage. The url for the webpage will be something like
> www.schoolapps.ml.org, I don't know right now.

> 4. I know how to open a new form by pressing a button or menuItem, but how
> can I chance so that it opens a new form and then closeing the one before.
> I don't know to close the form before, so there can be 2-4 forms open at the
> same time and thats a problem.
> ----------------------------------------

> If you have any suggestions please post it to me.

> If you want to mail me then use b...@get2net.dk

> Thank you for reading, and I hope you can help me.

Other Threads