writing to and reading from file
Posted: Thu Jun 27, 2013 9:32 pm
Dear all,
I heard about liveCode for the first time while attending the amazing Computing at Schools conference recently where I had the pleasure to meet Kevin and experience this amazing software first hand. I am learning how to use it and plan to teach Computing using this in the near future.
I have been working through the Computing course exemplar programming assignments and have hit a wall. I am sure my understanding is the issue, but cannot find (after many hours) a page online which guides me through this issue.
I have a simple card which takes a name and score and saves it to a text file as follows:
1. I do not know how to append new name/score combos onto the end of the file.
I then have a card which attempts to read this information in and put it onto a data grid:
I have the data grid column headers already set up. I want it (at this stage) to simply display a list of the entries in the text file.
I cannot work out how to save the name/score combo from the 2 text fields in such a way as its friendly to the import mechanism. When I have put more than 1 set of values into the save.txt field it has imported into one line of the data grid.
Any assistance would be warmly received. I need to get better at this before teaching students!
Dermot Mc Laughlin
I heard about liveCode for the first time while attending the amazing Computing at Schools conference recently where I had the pleasure to meet Kevin and experience this amazing software first hand. I am learning how to use it and plan to teach Computing using this in the near future.
I have been working through the Computing course exemplar programming assignments and have hit a wall. I am sure my understanding is the issue, but cannot find (after many hours) a page online which guides me through this issue.
I have a simple card which takes a name and score and saves it to a text file as follows:
1. I do not know how to append new name/score combos onto the end of the file.
Code: Select all
on mouseUp
local strName, strScore, strNew, strCurrent
put field "fldName" into strName
put field "fldScore" into strScore
--answer strName
put the effective filename of this stack into thePath
set the itemDelimiter to slash
put "save.txt" into the last item of thePath
put strName & tab & strScore & tab into strNew
put strName & tab & strScore into URL("file:" & thePath)
end mouseUp
I have the data grid column headers already set up. I want it (at this stage) to simply display a list of the entries in the text file.
Code: Select all
on openCard
--answer "open"
local strData
put the effective filename of this stack into thePath
set the itemDelimiter to slash
put "save.txt" into the last item of thePath
put URL("file:" & thePath) into strData
--answer strData
--put false into firstLineIsNames
set the dgText[strData] of group "Scores" to strData
end openCard
Any assistance would be warmly received. I need to get better at this before teaching students!
Dermot Mc Laughlin