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!
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller
-
Michaellad
- Posts: 12
- Joined: Tue Nov 15, 2016 12:17 pm
Post
by Michaellad » Fri Dec 09, 2016 2:34 pm
i have to make my code display in this format..
The most popular method of sales is XXXXX
The total money raised for charity is £XXXXX
But i am unsure how to do this as the help i was given did not format it in this way.
Code: Select all
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
-
Klaus
- Posts: 14191
- Joined: Sat Apr 08, 2006 8:41 am
-
Contact:
Post
by Klaus » Fri Dec 09, 2016 2:52 pm
Hi Michael,
not sure, but do you mean something like this:
...
put "The total money raised for charity is:" && "£" & totalamount into line 5 of fld "fresult"
...
?
Best
Klaus
-
dunbarx
- VIP Livecode Opensource Backer

- Posts: 10317
- Joined: Wed May 06, 2009 2:28 pm
Post
by dunbarx » Fri Dec 09, 2016 2:54 pm
Hi.
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?
Craig Newman
-
MaxV
- Posts: 1580
- Joined: Tue May 28, 2013 2:20 pm
-
Contact:
Post
by MaxV » Mon Dec 12, 2016 2:29 pm
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
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"
set the pMyText of me to MyText
end if
end read_in
on display_answer
put the pMyText of me into MyText
put 0 into totalamount
repeat for each line tLine in MyText
put item 1 of tLine into buyername
put item 2 of tLine into buyersurname
put item 3 of tLine into numberTickets
put max(numberTickets,totalamount) into totalAmount
put buyername & tab & buyersurname & tab & numbertickets & return after field "fresult"
end repeat
put 0 into tickets
put 10 into maxtickets
set itemdel to tab #changed itemedel!!!
put (the number of lines of field "fresult" ) - 1 into tickets
put "The total money raised for charity is: £" & round(totalamount) & return after fld "fresult"
end display_answer
on findingsales
put the pMyText of me into MyText
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
end repeat
put ("W = " & Wtickets && "s = " & Stickets) after fld "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