Getting the sum of numbers with decimals
Posted: Sun Jun 30, 2013 3:25 am
Hi all,
It's hard for me to ask for help. I love to intuit things on my own but admittedly, I am a huge beginner and have reached an impasse after spending what seems like an inordinate amount of time trying to solve a seemingly simple problem.
I am writing a tiny program that reads the contents of transaction files and isolates the dollar amount to a field. Although it is exceedingly simple, an application like this is very useful in my department. Anyway....
The program is successfully reading the files and reporting the dollar amounts to a field named "Total" but NOW I'm trying to add up all of these amounts to get a total sum. I keep striking out. When using the sum function it keeps telling me the numbers I'm trying to add up aren't numbers (which I know is because of the decimal). I've tried removing the decimal and using the sum of fld "Total" but it still errors out. Maybe I can't use the sum function on a field or variable?
Can someone please help?
It's hard for me to ask for help. I love to intuit things on my own but admittedly, I am a huge beginner and have reached an impasse after spending what seems like an inordinate amount of time trying to solve a seemingly simple problem.
I am writing a tiny program that reads the contents of transaction files and isolates the dollar amount to a field. Although it is exceedingly simple, an application like this is very useful in my department. Anyway....
The program is successfully reading the files and reporting the dollar amounts to a field named "Total" but NOW I'm trying to add up all of these amounts to get a total sum. I keep striking out. When using the sum function it keeps telling me the numbers I'm trying to add up aren't numbers (which I know is because of the decimal). I've tried removing the decimal and using the sum of fld "Total" but it still errors out. Maybe I can't use the sum function on a field or variable?
Code: Select all
on mouseUp
local tFileName
local tFileCount
local tOutput
local tTxntotal
answer files "Choose your TRANS files:"
put it into fld "Files"
put number of lines in fld "Files" into tFileCount //get number of transactions selected
put "Transactions Processed:"&&tFileCount into fld "Processed"
repeat for number of lines in fld "Files" // loop to open and parse each file
put line tFileCount in fld "Files" into tFileName //starting with last file first
open file tFileName for read //open transaction
read from file tFileName at 1 until EOF //read entire transaction
put it into tOutput //store output
put offset ("BATCHAMT", tOutput) into tTxnTotal //start search for check total
read from file tFileName at tTxnTotal for 7 characters //isolate total
put it into tTxnTotal
replace space with empty in tTxntotal //strip whitespace
put tTxnTotal after field "Total" //write the total of each transaction to field Total
subtract 1 from tFileCount //decrement filename each time loop runs
end repeat
end mouseUp