Page 1 of 1

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

Posted: Tue Feb 18, 2014 3:06 am
by herveyq
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.

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

Posted: Tue Feb 18, 2014 4:27 am
by Simon
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

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

Posted: Wed Feb 19, 2014 3:47 pm
by MaxV
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:

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

Posted: Thu Feb 20, 2014 2:12 am
by herveyq
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.

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

Posted: Thu Feb 20, 2014 2:50 am
by Simon
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

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

Posted: Thu Feb 20, 2014 3:20 am
by herveyq
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

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

Posted: Thu Feb 20, 2014 4:01 am
by Simon
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