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 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.
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.
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 answerfile"Please choose a file to read into your stack." iftheresultisnot"cancel"THEN put it into myText putURL ("file:" & myText) intofield"output1" endif end getfile
on readfile putfield"output1"into myText#getFile message already sent the text into field output1 put0into maximum setitemdeltocomma repeatforeachline myRow in myText #array students is: [name][surname]["sum_of_marks"]["number_of_marks"] additem3of myRow to students[(item1of myRow)] [(item2of myRow)]["sum_of_Marks"] # sum of the marks add1to students[item1of myRow][item2of myRow]["Number_of_Marks"] # number of the marks endrepeat #now we calculate percentages repeatforeachkey tName in students repeatforeachkey 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 endif endrepeat endrepeat answer"The student with the highest percentage is " & winner & " with percentage of " & round(maximum) end readfile #####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