Currency Problems
Author Message Currency Problems

I have written a program and need to add to Amount together depending on the
hours eg
var price,Total:real;

Jobprice.caption:="1,250.00"
TotalJobpeice.caption:="0.00"
TotalHours.text:="4";

t:=strtoint(TotalHours.text);
st:=JobPrice.text;
Delete(st,1,1);  { this bit remove the symbol }
val(st,Price,err);
Total:=0.00;
for i:=0 to t do Total:=Total+Price;
str(total:12:2,st);
TotalJobPrice.text:=st;

when i run it the value of price=2 and not 1,250.00 * 4

Thank You
Steve

Wed, 18 Jun 1902 08:00:00 GMT  Currency Problems

Quote:
> I have written a program and need to add to Amount together depending on
the
> hours eg
> var price,Total:real;

> Jobprice.caption:="1,250.00"
> TotalJobpeice.caption:="0.00"
> TotalHours.text:="4";

>     t:=strtoint(TotalHours.text);
>    st:=JobPrice.text;
>    Delete(st,1,1);  { this bit remove the symbol }
>    val(st,Price,err);
>    Total:=0.00;
>    for i:=0 to t do Total:=Total+Price;
>    str(total:12:2,st);
>    TotalJobPrice.text:=st;

> when i run it the value of price=2 and not 1,250.00 * 4

uummm - if JobPrice.Caption = "1,250.00", then why is st = JobPrice.text,
not JobPrice.caption???

HTH

Karl

Wed, 18 Jun 1902 08:00:00 GMT  Currency Problems

Quote:
> I have written a program and need to add to Amount together depending on
the
> hours eg
> var price,Total:real;

> Jobprice.caption:="1,250.00"
> TotalJobpeice.caption:="0.00"
> TotalHours.text:="4";

>     t:=strtoint(TotalHours.text);
>    st:=JobPrice.text;
>    Delete(st,1,1);  { this bit remove the symbol }
>    val(st,Price,err);

As usual, Delphi makes no errors. At this point, price contains 1 (the first
1 in the field) and  err contains 2 (the first non numeric character).

As much as possible, you should use text fields only to display numeric
values, and assign numeric variables to store and manipulate your numeric
data.

var totPrice : Currency;
totHours : Integer;

Hours.Caption := IntTosStr(totHours);

etc.

Also, try to forget some of the Turbo Pascal coding and code in Delphi.

Quote:
>    Total:=0.00;
>    for i:=0 to t do Total:=Total+Price;
>    str(total:12:2,st);
>    TotalJobPrice.text:=st;

> when i run it the value of price=2 and not 1,250.00 * 4

> Thank You
> Steve

Wed, 18 Jun 1902 08:00:00 GMT  Currency Problems
Thank very All
I spoke to Karl and now it work's a treat i have now added the following:
i still had to delete the and the , but it works fine
thank you again
Steve

t:=strtoint(TotalHours.text);
st:=JobPrice.text;
if st='' then Delete(st,1,1);
for i:=0 to Length(st) do if st[i]=',' then delete(st,i,1);
Price:=StrToCurr(st);
Total:=0;
for i:=1 to t do Total:=Total+Price;
st:=CurrToStr(Total);
TotalJobPrice.text:=st;

Quote:

> > I have written a program and need to add to Amount together depending on
> the
> > hours eg
> > var price,Total:real;

> > Jobprice.caption:="1,250.00"
> > TotalJobpeice.caption:="0.00"
> > TotalHours.text:="4";

> >     t:=strtoint(TotalHours.text);
> >    st:=JobPrice.text;
> >    Delete(st,1,1);  { this bit remove the symbol }
> >    val(st,Price,err);

> As usual, Delphi makes no errors. At this point, price contains 1 (the
first
> 1 in the field) and  err contains 2 (the first non numeric character).

> As much as possible, you should use text fields only to display numeric
> values, and assign numeric variables to store and manipulate your numeric
> data.

> var totPrice : Currency;
>       totHours : Integer;

> Hours.Caption := IntTosStr(totHours);

> etc.

> Also, try to forget some of the Turbo Pascal coding and code in Delphi.

> >    Total:=0.00;
> >    for i:=0 to t do Total:=Total+Price;
> >    str(total:12:2,st);
> >    TotalJobPrice.text:=st;

> > when i run it the value of price=2 and not 1,250.00 * 4

> > Thank You
> > Steve

Wed, 18 Jun 1902 08:00:00 GMT

 Page 1 of 1 [ 4 post ]

Relevant Pages