How to save and load card data (on card file db)

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
herveyq
Posts: 3
Joined: Tue Feb 18, 2014 3:00 am

How to save and load card data (on card file db)

Post by herveyq » Tue Feb 18, 2014 3:06 am

OK so I am slow learner, must be getting too old for this, but how do i save data input into card fields to card db, and then load the data on opening the stack again?

Thanks in advance for the help.
Regards

Gil

Simon
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3901
Joined: Sat Mar 24, 2007 2:54 am

Re: How to save and load card data (on card file db)

Post by Simon » Tue Feb 18, 2014 4:27 am

Hi herveyq,
Welcome to the forum!

Let me ask a question first. How many fields will need to be recorded in the end? 100's/1000s/10000s/more?
You mention db (database), now I know people who will swear an Excel spreadsheet is a database, but it's not. Do you already have a db background?

liveCode gives you plenty of ways to record info.externally. db/txt/stack

Simon
I used to be a newbie but then I learned how to spell teh correctly and now I'm a noob!

MaxV
Posts: 1580
Joined: Tue May 28, 2013 2:20 pm
Contact:

Re: How to save and load card data (on card file db)

Post by MaxV » Wed Feb 19, 2014 3:47 pm

If there are few data I suggest arrayEncode and arraydecode into a file, otherwise use SQLite db, since SQLite is embedded in Livecode.
See also:
Livecode Wiki: http://livecode.wikia.com
My blog: https://livecode-blogger.blogspot.com
To post code use this: http://tinyurl.com/ogp6d5w

herveyq
Posts: 3
Joined: Tue Feb 18, 2014 3:00 am

Re: How to save and load card data (on card file db)

Post by herveyq » Thu Feb 20, 2014 2:12 am

Hi Simon and Max,

I thought it was possible to save small amounts of information on the stack, so that is one thing for this project to be small and self contained on a phone. The other option is to use the included database or MYSQL for my larger base with external.

Simon, I started looking at database against spreadsheet in 1982. I kept to known RAD programs, Clarion, Windev and produced large database systems and a ticketing system for passenger transport. Now I am looking at hobby use only and wanted to get away from expensive options where there would be no financial return so looked around and came to what appears to have been Revolution.

After a heart attack, getting back on the wagon has it's challenges, so your help is most appreciated.

Fields, usually only in the hundreds using the KISS principal. Never anything really clever that can go wrong always KISS and I don't have to support as it just keeps running.
Regards

Gil

Simon
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3901
Joined: Sat Mar 24, 2007 2:54 am

Re: How to save and load card data (on card file db)

Post by Simon » Thu Feb 20, 2014 2:50 am

Hi herveyq,
First thing to know is that a standalone (.exe .app .apk whatever) cannot save information to itself. None Nil Nada.
What applications do is save information to external files.

New stack 1 button, in the button script

Code: Select all

on mouseUp
   set the defaultFolder to specialFolderPath("desktop") --This is the folder where things will be saved to
   if there is a file "Test.txt" then
      put url "file:Test.txt" into readFile --readFile is a made up variable name, almost any word will do but some are "reserved words"
      answer readFile --show the contents of the file
   else
      put "I was read from disk" into writeFile
      put writeFile into url "file:Test.txt" --write a new file
      put url "file:Test.txt" into imANewFile
      answer imANewFile --show the contents of the file
   end if
end mouseUp
Now when you press the button a new file will be created and read (if it's not there already).
Edit Test.txt with an editor and change the text inside and save the file.
Now when you click on the button it will show the new text.

Give that a go and tell me how you get on, we can talk about sqLite database later as well if you like.

Simon
I used to be a newbie but then I learned how to spell teh correctly and now I'm a noob!

herveyq
Posts: 3
Joined: Tue Feb 18, 2014 3:00 am

Re: How to save and load card data (on card file db)

Post by herveyq » Thu Feb 20, 2014 3:20 am

Thanks Simon,

I probably go the sqLite route to maintain data types, even though I only want to record one record and tect will do for that. Will test and advise.

Gil
Regards

Gil

Simon
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3901
Joined: Sat Mar 24, 2007 2:54 am

Re: How to save and load card data (on card file db)

Post by Simon » Thu Feb 20, 2014 4:01 am

Hi Gil,
Lets add some more
put
"I am line 1 of file Test.txt"
"I am line 2 of file Test.txt"
into the Test.txt file and save it.
Replace

Code: Select all

answer imANewFile --show the contents of the file
with

Code: Select all

answer line 2 of imANewFile --show the contents of the file
With that you can see how to build a complete record of the fields contents.

Simon
I used to be a newbie but then I learned how to spell teh correctly and now I'm a noob!

Post Reply