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!
on mouseUp
initialise
read_in MyText
display_answer buyerinfo, buyername, buyersurname, numbertickets, MyText
findingsales tTLA
end mouseUp
on initialise
put "" into MyText
put "" into buyerinfo
put "" into buyername
put "" into buyersurname
put 0 into numbertickets
put 0 into total
end initialise
on read_in @MyText
Answer file "Please choose a file to read into your LiveCode stack"
if the result is not "cancel" then
put it into MyText
put url("file:" & MyText) into MyText
put it into fld "output1"
end if
end read_in
on display_answer MyText, @buyerinfo, @buyername, @buyersurname, @numbertickets
local loop
repeat with loop = 1 to number of lines of MyText
put line loop of MyText into buyerinfo
split buyerinfo by comma
put buyerinfo[1] into buyername[loop]
put buyerinfo[2] into buyersurname[loop]
put buyerinfo[3] into numbertickets[loop]
put buyername[loop] & tab & buyersurname[loop] & tab & numbertickets[loop] into line loop of field "fresult"
end repeat
local tickets, totalamount, maxtickets
put 0 into tickets
put 10 into maxtickets
put numbetickets[1] into totalamount
repeat with loop = 2 to number of lines of MyText
if numbertickets[loop] > totalamount then
put numbertickets[loop] into totalamount
put loop into tickets
end if
end repeat
set numberformat to "0"
put "The total money raised for charity is:" &&totalamount into line 5 of fld "fresult"
end display_answer
on findingsales
set the caseSensitive to true
repeat until MyText is empty
put char 1 of MyText into HOLDER
if HOLDER = "s" then
add 1 to Stickets
end if
if HOLDER = "W" then
add 1 to Wtickets
end if
delete char 1 of tTLA
end repeat
put ("W = " & Wtickets && "s = " & Stickets) into fld "fResult"
end findingsales
not sure, but do you mean something like this:
...
put "The total money raised for charity is:" && "£" & totalamount into line 5 of fld "fresult"
...
?
Hard to know what is wrong without knowing what the value of the file you access is. Can a literal piece of data substitute? Can you provide such a sample of text?
Hi Michaellad,
I modified your code in more livecode way, it's shorter and simpler, and I added the £ sign. Here is the new code:
########CODE####### on mouseUp read_in MyText display_answer findingsales end mouseUp
on read_inMyText Answerfile"Please choose a file to read into your LiveCode stack" iftheresultisnot"cancel"then put it into MyText puturl("file:" & MyText) into MyText put it intofld"output1" setthe pMyText ofmeto MyText endif end read_in on display_answer putthe pMyText ofmeinto MyText put0into totalamount repeatforeachline tLine in MyText putitem1of tLine into buyername putitem2of tLine into buyersurname putitem3of tLine into numberTickets putmax(numberTickets,totalamount) into totalAmount put buyername & tab & buyersurname & tab & numbertickets & returnafterfield"fresult" endrepeat put0into tickets put10into maxtickets setitemdeltotab#changed itemedel!!! put (thenumberoflinesoffield"fresult" ) - 1into tickets put"The total money raised for charity is: £" & round(totalamount) & returnafterfld"fresult" end display_answer on findingsales putthe pMyText ofmeinto MyText setthecaseSensitivetotrue repeatuntil MyText isempty putchar1of MyText into HOLDER if HOLDER = "s"then add1to Stickets endif if HOLDER = "W"then add1to Wtickets endif endrepeat put ("W = " & Wtickets && "s = " & Stickets) afterfld"fResult" end findingsales
#####END OF CODE#####
Livecode Wiki: http://livecode.wikia.com
My blog: https://livecode-blogger.blogspot.com
To post code use this: http://tinyurl.com/ogp6d5w