taariq 0 Posted September 22, 2023 Good day Plz note I am a newbie to Delphi and still learning but enjoying it... I need help with calculations please... I got total sum via database by using the following code that is working... dmuse.dmDBuse.FDQueryMaterialTotal.Open('SELECT SUM(COST) AS TC FROM MATERIAL WHERE ORDERNO=:d',[dbOrderNo.Text]); Showmessage(format( 'Total for Material OrderNo %s is %m',[dbOrderNo.text,dmuse.dmDBuse.FDQueryMaterialTotal.FieldbyName('TC').asCurrency])); tMaterial.text:=Format('%m',[dmuse.dmDBuse.FDQueryMaterialTotal.fieldbyName('TC').asCurrency]); dmuse.dmDBuse.fdQueryTraveling.Open('SELECT SUM(COST) AS TC FROM TRAVELING WHERE ORDERNO=:d',[dbOrderNo.Text]); Showmessage(format( 'Total for Traveling OrderNo %s is %m',[dbOrderNo.text,dmuse.dmDBuse.fdQueryTraveling.FieldbyName('TC').asCurrency])); tTraveling.text:=Format('%m',[dmuse.dmDBuse.fdQueryTraveling.fieldbyName('TC').asCurrency]); But here is my issue - trying to add the two values together Code I tried but get error - Code I am using... procedure TForm1.Button2Click(Sender: TObject); var tMaterial, tTraveling, tTotalCost: Currency ; usSet : TFormatSettings; begin usSet:=TFormatSettings.Create('EN_US'); tMaterial := StrToCurr (lbMaterial.Caption,usSet) ; tTraveling := StrToCurr (lbTraveling.Caption,usSet) ; tTotalCost := tMaterial + tTraveling; tProjectCosting.text := CurrToStrF(tTotalCost, ffCurrency, 2); end; Please help Thank you Share this post Link to post
David Heffernan 2345 Posted September 22, 2023 The error message seems quite clear. Do you know how to use the debugger to inspect vakues being passed to StrToCurr? Share this post Link to post
taariq 0 Posted September 22, 2023 Thanks for quick reply Do you know how to use the debugger to inspect vakues being passed to StrToCurr? > this will be so helpful - how do I inspect error Thank you Share this post Link to post
David Heffernan 2345 Posted September 22, 2023 Find a tutorial on how yo use a debugger 1 Share this post Link to post
taariq 0 Posted September 22, 2023 Good day I got a nice google video on how to run and use debugger... What I see now ...but still don't understand Share this post Link to post
David Heffernan 2345 Posted September 22, 2023 Set a break point on the line where the error occurs. When the code breaks there inspect the value of the argument passed to StrToCur. Share this post Link to post
Stano 143 Posted September 22, 2023 I would first of all use the corresponding components on the form. If I have a Currency type, I wouldn't use a component that works with text! It's best not to use the StrToCurr() and CurrToStr() functions at all. Share this post Link to post
taariq 0 Posted September 22, 2023 thanks for reply what I get, when using text and no StrTo Share this post Link to post
taariq 0 Posted September 22, 2023 Good day I change the name of the edit box and the var Share this post Link to post
Lajos Juhász 293 Posted September 22, 2023 https://docwiki.embarcadero.com/Libraries/Sydney/en/System.SysUtils.StrToCurr Thousand separators and currency symbols are not allowed in the string. If the string doesn't contain a valid value, StrToCurr raises an EConvertError exception. Share this post Link to post
David Heffernan 2345 Posted September 22, 2023 "Material is not a valid floating point value" Ask yourself why you are trying to convert the text Material to a numeric value. Do you know why yet?? Share this post Link to post