Board index » delphi » problem to solve using numbers in delphi (using Val() and FloatToStrF() )

problem to solve using numbers in delphi (using Val() and FloatToStrF() )

hi all i'm new to this delphi stuff so sorry if my terminology is not
quite right.
As part of my course at university (and probably for use in my future
career) i have begun to start learning how to use delphi. Any help
would be much appreciated.

The problem i have been set is

Add to a form the following items, all appropriately named:
1 editbox that allows the user to key in a number
1 label that displays the answer to the calculation you perform.
1 button that when clicked multiplies the input number by 10

The problem is that the TEditBox Caption and the TLabel Caption are
both strings whereas i have to do my calculation with numbers - so how
do i alter the datatype.

I think i have to use the functions Val() and FloatToStrF() to solve
this problem but am not sure

any help you could offer would be very er....helpful

thanks Henry

 

Re:problem to solve using numbers in delphi (using Val() and FloatToStrF() )


Henry, use the StrToFloat or StrToInt function to convert the strings to
numbers, then use the IntToStr or FloatToStr or FloatToStrF function to
convert the calculated number back to a string.  Hope that helps.

Carrie

Quote
Henry wrote:
> hi all i'm new to this delphi stuff so sorry if my terminology is not
> quite right.
> As part of my course at university (and probably for use in my future
> career) i have begun to start learning how to use delphi. Any help
> would be much appreciated.

> The problem i have been set is

> Add to a form the following items, all appropriately named:
> 1 editbox that allows the user to key in a number
> 1 label that displays the answer to the calculation you perform.
> 1 button that when clicked multiplies the input number by 10

> The problem is that the TEditBox Caption and the TLabel Caption are
> both strings whereas i have to do my calculation with numbers - so how
> do i alter the datatype.

> I think i have to use the functions Val() and FloatToStrF() to solve
> this problem but am not sure

> any help you could offer would be very er....helpful

> thanks Henry

Re:problem to solve using numbers in delphi (using Val() and FloatToStrF() )


On 4 Feb 2003 11:01:44 -0800, akain...@hotmail.com (Henry) wrote:

Quote
>hi all i'm new to this delphi stuff so sorry if my terminology is not
>quite right.
>As part of my course at university (and probably for use in my future
>career) i have begun to start learning how to use delphi. Any help
>would be much appreciated.

>The problem i have been set is

>Add to a form the following items, all appropriately named:
>1 editbox that allows the user to key in a number
>1 label that displays the answer to the calculation you perform.
>1 button that when clicked multiplies the input number by 10

>The problem is that the TEditBox Caption and the TLabel Caption are
>both strings whereas i have to do my calculation with numbers - so how
>do i alter the datatype.

The first thing to keep in mind is that ALL communication from the
keyboard and to edit boxes and labels is character based. Delphi
controls and functions let you handle the characters as strings. you
will need to explicitly change to/from strings to numerics in your
code. eg, myinteger := 3 + StrToInt(editbox.text);
Look up strtoint in the help and follow the 'see also' links to other
functions. Also look up TMaskEdit. This is a good way to keep the user
from typing letters where only numbers should go.

hth,
Dan

- Show quoted text -

Quote
>I think i have to use the functions Val() and FloatToStrF() to solve
>this problem but am not sure

>any help you could offer would be very er....helpful

>thanks Henry

Other Threads