Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!
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?
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
I think I might've figured it out. I haven't tried it yet but I think my numbers need to be comma delimited to be processed by the sum function. I think I was wrong about the decimal messing it up. Going to try it now.
on mouseUp
put empty into total
repeat with count = 1 to the number of lines of fld 1
add line count of fld 1 to total
end repeat
put total
end mouseUp
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 of fld "Files" into tFileCount //get number of transactions selected
put "Transactions Processed:"&&tFileCount into fld "Processed"
## Accessing FIELDS is much slower than putting their content into a variable first!
put fld "Files" into tFileList
## Never access a field in a repeat loop, see above and below:
put empty into tFieldTotal
repeat with i = tFileCount down to 1
put line tFileCount of tFileList into tFileName //starting with last file first
## The one liner to put a file into a variable!
put url("file:" & tFileName) into tOutput
put offset ("BATCHAMT", tOutput) into tTxnTotal //start search for check total
## This one might need a little adjustment ;-)
put char tTxnTotal to (tTxnTotal + 7) of tOutput into tTxnTotal
replace space with empty in tTxntotal //strip whitespace
## Write to variable first...
put tTxnTotal after tFieldTotal
end repeat
## ...then to field!
put tFieldTotal after field "Total" //write the total of each transaction to field Total
end mouseUp
This completely stumped me until I saw that the comma fixed it. I am frequently thrown by the fact that this forum is international, and that many posts are all about mobile.
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 of fld "Files" into tFileCount //get number of transactions selected
put "Transactions Processed:"&&tFileCount into fld "Processed"
## Accessing FIELDS is much slower than putting their content into a variable first!
put fld "Files" into tFileList
## Never access a field in a repeat loop, see above and below:
put empty into tFieldTotal
repeat with i = tFileCount down to 1
put line tFileCount of tFileList into tFileName //starting with last file first
## The one liner to put a file into a variable!
put url("file:" & tFileName) into tOutput
put offset ("BATCHAMT", tOutput) into tTxnTotal //start search for check total
## This one might need a little adjustment ;-)
put char tTxnTotal to (tTxnTotal + 7) of tOutput into tTxnTotal
replace space with empty in tTxntotal //strip whitespace
## Write to variable first...
put tTxnTotal after tFieldTotal
end repeat
## ...then to field!
put tFieldTotal after field "Total" //write the total of each transaction to field Total
end mouseUp
Best
Klaus
Hey Klaus!
I just saw this. Thank you so much for your helpful response. I have implemented your suggestions. You have been a great resource.