Page 1 of 1
Wont display
Posted: Tue Jan 10, 2017 1:10 pm
by Michaellad
Code: Select all
on mouseUp
initialise
get_file MyText
read_file MyText, ticketsales, arraycustomerID, arrayticketid, arrayticketno, arraymethod
calculate_popular arraymethod, mostused
calculate_total MyText, arraytickets, totalsale
display_data mostused, totalsale
export_data
end mouseUp
on initialise
put "" into MyText
put "" into ticketsales
put "" into arraycustomerID
put "" into arrayticketID
put 0 into arrayticketno
put "" into arraymethod
put "" into mostused
put 0 into totalsale
put "" into outputcontent
end initialise
on get_file @MyText
Answer file "Please choose a file to read in:"
IF the result is not "cancel" THEN
put it into MyText
put url ("file:" & MyText) into MyText
end if
end get_file
on read_file MyText, ticketsales, arraycustomerID, arrayticketid, arrayticketno, arraymethod
repeat with loop = 1 to number of lines of MyText
put line loop of MyText into ticketsales
split ticketsales by comma
put ticketsales[1] into arraycustomerID[loop]
put ticketsales[2] into arrayticketid[loop]
put ticketsales[3] into arrayticketno[loop]
put ticketsales[4] into arraymethod[loop]
end repeat
end read_file
on calculate_popular arraymethod, mostused
local school, web
put 0 into school
put 0 into web
repeat with loop = 1 to number of lines of MyText
IF arraymethod[loop] = "S" THEN add 1 to school
IF arraymethod[loop]= "W" THEN add 1 to web
end repeat
IF school>web THEN
put " sold by the school" into mostused
ELSE
put "sold online" into mostused
end if
end calculate_popular
on calculate_total MyText, arraytickets, totalsale
local thesale
put 0 into thesale
repeat with loop = 1 to number of lines of MyText
IF arraytickets[loop] = "W1" OR "W2" OR "W3" OR "T1" OR "T2" OR "T3" THEN
put arrayticket[loop] *5 into thesale
put thesale into totalsale
ELSE
put arraytickets[loop] *10 into thesale
put thesale into totalsale
end IF
end repeat
end calculate_total
on display_data mostused, totalsale
local TDate
put the date into TDate
convert TDate to dateitems
put item 1 of TDate into year
put "Essell Academy Choral Shield" & year into line 1 of field output1
put "The most popular method of pay is:" & mostused into line 3 of field output1
put "The total money raised for charity is:" & totalsale into line 4 of field output1
end display_data
on export_data arrayticketid, arraycustomerid, arrayticketno, arraymethod, MyText
local TDate
put the date into TDate
convert TDate to dateitems
put item 1 of TDate into year
repeat with loop = 1 to number of lines of MyText
IF arrayticketid[loop]= "F1" OR "F2" OR "F3"
THEN put arraycustomerid[loop] & arrayticketid[loop] & arrayticketno[loop] & arraymethod into line loop of field "output2"
end repeat
Ask file "Please choose where you want to save the data"
IF the result is not "cancel" THEN
put it into MyText
put field "output" into ticketsales
end if
end export_data
This will not display to the output can someone help?
(Its supposed to be this long as it is part of my coursework?)
Re: Wont display
Posted: Tue Jan 10, 2017 1:48 pm
by Klaus
Déjà vue?
You are passing empty, and thus useless!, parameters (or empty reference -> @myText) to your handlers/functions,
but you need LOCAL variables here, so ALL the handlers/functions in this script can access them:
Code: Select all
local ticketsales, arraycustomerID, arrayticketid, arrayticketno, arraymethod
on mouseUp
initialise
get_file
read_file
calculate_popular
calculate_total
display_data
export_data
end mouseUp
## etc...
And in your "export_data" hanlder you are asking for a filename, store the filename in myText
but do NOT write the info to that file!
Code: Select all
...
Ask file "Please choose where you want to save the data"
IF the result is not "cancel" THEN
put it into MyText
put field "output" into ticketsales
end if
end export_data
Best
Klaus
Re: Wont display
Posted: Tue Jan 10, 2017 1:51 pm
by Klaus
P.S. It is good style to also visit all of your previous postings and maybe leave a little "thank you" or something like that!

Re: Wont display
Posted: Wed Jan 11, 2017 2:58 pm
by Michaellad
Thank you Klaus, I appreciate the help.
Re: Wont display
Posted: Wed Jan 11, 2017 3:40 pm
by Michaellad
Code: Select all
local ticketsales, arraycustomerID, arrayticketID, arrayticketno, arraymethod, MyText
on mouseUp
initialise
get_file
read_file MyText, ticketsales, arraycustomerID, arrayticketID, arrayticketno, arraymethod
calculate_popular
calculate_total
display_data
export_data
end mouseUp
on initialise
put "" into MyText
put "" into ticketsales
put "" into arraycustomerID
put "" into arrayticketID
put 0 into arrayticketno
put "" into arraymethod
put "" into mostused
put 0 into totalsale
put "" into outputcontent
put 0 into thesale
end initialise
on get_file
Answer file "Please choose a file to read in:"
IF the result is not "cancel" THEN
put it into MyText
put url ("file:" & MyText) into MyText
end if
end get_file
on read_file MyText, ticketsales, arraycustomerID, arrayticketID, arrayticketno, arraymethod
local loop
repeat with loop = 1 to number of lines of MyText
put line loop of MyText into ticketsales
split ticketsales by comma
put ticketsales[1] into arraycustomerID[loop]
put ticketsales[2] into arrayticketID[loop]
put ticketsales[3] into arrayticketno[loop]
put ticketsales[4] into arraymethod[loop]
end repeat
put arraycustomerID into line 1 of field "output2"
end read_file
on calculate_popular arraymethod, mostused
local school, web
put 0 into school
put 0 into web
repeat with loop = 1 to number of lines of MyText
IF arraymethod[loop] = "S" THEN add 1 to school
IF arraymethod[loop]= "W" THEN add 1 to web
end repeat
IF school>web THEN
put " sold by the school" into mostused
ELSE
put "sold online" into mostused
end if
end calculate_popular
on calculate_total MyText, arrayticketID, totalsale, thesale
repeat with loop = 1 to number of lines of MyText
IF arrayticketID[loop] = "W1" OR "W2" OR "W3" OR "T1" OR "T2" OR "T3" THEN
put arrayticketID[loop] *5 into thesale
put thesale into totalsale
ELSE
put arrayticketID[loop] *10 into thesale
put thesale into totalsale
end IF
end repeat
end calculate_total
on display_data mostused, totalsale, TDate, year
put the date into TDate
convert TDate to dateitems
put item 1 of TDate into year
put "Essell Academy Choral Shield" & year into line 1 of field output1
put "The most popular method of pay is:" & mostused into line 3 of field output1
put "The total money raised for charity is:" & totalsale into line 4 of field output1
end display_data
on export_data arrayticketID, arraycustomerID, arrayticketno, arraymethod, MyText
local TDate
put the date into TDate
convert TDate to dateitems
put item 1 of TDate into year
repeat with loop = 1 to number of lines of MyText
IF arrayticketID[loop]= "F1" OR "F2" OR "F3"
THEN put arraycustomerID[loop] & arrayticketID[loop] & arrayticketno[loop] & arraymethod into line loop of field "output2"
end repeat
Ask file "Please choose where you want to save the data"
IF the result is not "cancel" THEN
put it into MyText
end if
end export_data
Ive made some changes but it still wont display.

Re: Wont display
Posted: Wed Jan 11, 2017 4:37 pm
by Klaus
WHAT does not get displayed and WHERE (field? File?)?
Btw, I thought we had beenn past the LOCAL thing?
With local variables you do NOT need to pass any parameter, that has been declared a local, as I wrote:
Code: Select all
local ticketsales, arraycustomerID, arrayticketid, arrayticketno, arraymethod
on mouseUp
initialise
get_file
read_file
calculate_popular
calculate_total
display_data
export_data
end mouseUp
## etc...
Hint:
Code: Select all
...
IF arrayticketID[loop] = "W1" OR "W2" OR "W3" OR "T1" OR "T2" OR "T3" THEN
...
Won't work!
This will:
Code: Select all
...
IF arrayticketID[loop] = "W1" OR arrayticketID[loop] ="W2" OR arrayticketID[loop] ="W3" OR arrayticketID[loop] ="T1" OR arrayticketID[loop] ="T2" OR arrayticketID[loop] = "T3" THEN
...
Re: Wont display
Posted: Wed Jan 11, 2017 5:38 pm
by Klaus
Hint 2:
Please hit the TAB key from time to time when writing scripts!
This way the engine will format your current handler/function nicely.
Hint 3 (which may probably cause your inconvenience):
ARRAYS cannot be displayed in a field!
You will need to "convert" them into a string first.
Re: Wont display
Posted: Wed Jan 11, 2017 5:45 pm
by dunbarx
ARRAYS cannot be displayed in a field!
Quite.
But they can be seen in the debugger directly if you set a breakpoint and examine the variable pane.
Craig Newman