writing to and reading from file

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

Post Reply
dmclaughlin
Posts: 2
Joined: Thu Jun 27, 2013 9:22 pm

writing to and reading from file

Post by dmclaughlin » 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.

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 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.

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
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

mwieder
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3581
Joined: Mon Jan 22, 2007 7:36 am
Contact:

Re: writing to and reading from file

Post by mwieder » Thu Jun 27, 2013 10:32 pm

Dermot:

1. Two ways to deal with this:

Code: Select all

put strName & tab & strScore& cr  after URL("file:" & thePath)
or

Code: Select all

put URL("file:" & thePath) into tScores
put strName & tab & strScore& cr  after tScores
put tScores into URL("file:" & thePath)

dmclaughlin
Posts: 2
Joined: Thu Jun 27, 2013 9:22 pm

Re: writing to and reading from file

Post by dmclaughlin » Fri Jun 28, 2013 12:38 pm

Thank you. I very much appreciate the fast response.

Post Reply