Page 1 of 1
Not displaying the percentage.
Posted: Fri Nov 18, 2016 3:23 pm
by Michaellad
Code: Select all
on mouseUp
initialise myText, arrayname, arraymark, arraypercentage, student
getfile myText
readfile student, arrayname, arraymark, arraypercentage
end mouseUp
on initialise @myText, @student, @arrayname, @arraymark, @arraypercentage
put "" into myText
put 0 into student
put "" into arrayname
put "" into arraymark
put 0 into arraypercentage
end initialise
on getfile @text
answer file "Please choose a file to read into your stack."
if the result is not "cancel" THEN
put it into myText
put URL ("file:" & myText) into field "output1"
end if
end getfile
on readfile student, arrayname, arraymark, arraypercentage
local maximum
local position
local loop
put 0 into arraypercentage
put 0 into maximum
put 0 into position
put 50 into student
repeat with loop = 1 to the number of lines of myText
put line loop of myText into student
split student by comma
put student[1] into arrayname[loop]
put student[2] into arrayfullname
put student[3] into arraymark[loop]
put arrayname[loop] & tab & arraymark[loop] & tab & arraypercentage[loop] into line 1 of field "output1"
end repeat
put arraymark[1] into maximum
repeat with loop = 2 to the number of lines of myText
if arraymark[loop] > maximum then
put arraymark[loop] into maximum
put loop into position
end if
end repeat
set numberformat to "0"
put "The student with the highest percentage is" & arrayname[position] & "with percentage of" & arraymark[loop] &" %" into line 2 of fld"output2"
end readfile
My code is not displaying the percentage or the name of the highest mark.
Re: Not displaying the percentage.
Posted: Fri Nov 18, 2016 5:27 pm
by dunbarx
I would say that myText is empty.
Try moving the local commands to the top of the script. Know that when you declare either local or global variables, they MUST reside ABOVE all handlers that need them. I bet this is your problem, since you seem more than able to drive LC.
Craig Newman
Re: Not displaying the percentage.
Posted: Fri Nov 18, 2016 6:59 pm
by Klaus
Hi Michael,
what Craig said!
Hint: myText will only hold the FILENAME of the file the user has selected and not its content!
And please check your earlier postings, the proposals (guesses to be honest) are already pile up here:
http://forums.livecode.com/viewtopic.php?f=7&t=28315
Best
Klaus
Re: Not displaying the percentage.
Posted: Fri Nov 18, 2016 11:02 pm
by Michaellad
Thanks for the help, I will try what you have told me when I get the chance.
Michaella
Re: Not displaying the percentage.
Posted: Tue Nov 22, 2016 12:20 pm
by Michaellad
How can I put the file into myText?
Re: Not displaying the percentage.
Posted: Tue Nov 22, 2016 1:34 pm
by Klaus
Michaellad wrote:How can I put the file into myText?
The same way as you put it into your field "output1"!

Re: Not displaying the percentage.
Posted: Tue Nov 22, 2016 2:48 pm
by MaxV
Michaellad wrote:...
My code is not displaying the percentage or the name of the highest mark.
Hi,
your code is not very livecode style, this is probably what you need:
########CODE#######
on mouseUp
getfile
readfile
end mouseUp
on getfile
answer file "Please choose a file to read into your stack."
if the result is not "cancel" THEN
put it into myText
put URL ("file:" & myText) into field "output1"
end if
end getfile
on readfile
put field "output1" into myText#getFile message already sent the text into field output1
put 0 into maximum
set itemdel to comma
repeat for each line myRow in myText
#array students is: [name][surname]["sum_of_marks"]["number_of_marks"]
add item 3 of myRow to students[(item 1 of myRow)] [(item 2 of myRow)]["sum_of_Marks"] # sum of the marks
add 1 to students[item 1 of myRow][item 2 of myRow]["Number_of_Marks"] # number of the marks
end repeat
#now we calculate percentages
repeat for each key tName in students
repeat for each key tSurname in students[tName]
put students[tName][tSurname]["sum_of_marks"] / students[tName][tSurname]["number_of_Marks"] into tperc
if tperc > maximum then
put tName & space & tSurname into winner
put tperc into maximum
end if
end repeat
end repeat
answer "The student with the highest percentage is " & winner & " with percentage of " & round(maximum)
end readfile
#####END OF CODE#####