datagrid not saving between launches on android

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: Klaus, FourthWorld, heatherlaine, kevinmiller

gurusonwheels
Posts: 31
Joined: Sat Apr 01, 2017 5:15 pm

datagrid not saving between launches on android

Post by gurusonwheels » Sat Apr 01, 2017 6:07 pm

when i make changes to the data in the datagrid while running in livecode
my changes are remembered .

however when i send to a android device . if i make data changes in the grid the changes revert at each launch .

i am 100% newbie so please be easy .

lol

Klaus
Posts: 11207
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: datagrid not saving between launches on android

Post by Klaus » Mon Apr 03, 2017 3:12 pm

Hi gurusonwheels,

standalones (for Mac, Win, Linux, iOS and Android) cannot and will not save themselves! NEVER!

So when opening an app it will look like at the time when you compiled the stack (created the standalone).
One approach to overcome this "inconvenience" is to write out the data and read it in the next time the app starts.
Here a lesson to get you started: http://lessons.livecode.com/m/4069/l/14 ... -on-mobile

For a datagrid of type TABLE you simple write and read -> the dgtext of grp "your datagrid here"


Best

Klaus

gurusonwheels
Posts: 31
Joined: Sat Apr 01, 2017 5:15 pm

Re: datagrid not saving between launches on android

Post by gurusonwheels » Tue Apr 04, 2017 12:55 pm

For a datagrid of type TABLE you simple write and read -> the dgtext of grp "your datagrid here"
not sure i understand what you mean by that

Klaus
Posts: 11207
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: datagrid not saving between launches on android

Post by Klaus » Tue Apr 04, 2017 1:07 pm

Hi guruonwheels,

I mean:
a. A datagrid can be of type TABLE, which is the default setting for newly created datagrids.
Something like a simple EXCEL spreadsheet. Only supports ONE line of text (and only text!) per "cell".
If you need a more advanced datagrid e.g. with buttons and images etc. then you need to set the datragrids type to FORM.
There is pulldown menu for that in the "Property inspector" palette.

b. To get the "content" of a datagrid you can do:

Code: Select all

...
## Save content of datagrid to file:
put the dgtext of grp  "your datagrid here" into tVariable
put tVariable into url("file:content_of_my_datagrid.txt")
...
To fill a datagrid with content you can SET this property of your datagrid:

Code: Select all

...
## Read file on disk and set the content of your datagrid to the content of that file:
put url("file:content_of_my_datagrid.txt") into tVariable
set the dgtext of grp "your datagrid here" to tVariable
...
If you have further questions, let them come :D
Unfortunately DATAGRIDS are the most complex beasts we have in Livecode.

Here some great learning resources for the basics of Livecode:
http://www.hyperactivesw.com/revscriptc ... ences.html

Best

Klaus

gurusonwheels
Posts: 31
Joined: Sat Apr 01, 2017 5:15 pm

Re: datagrid not saving between launches on android

Post by gurusonwheels » Tue Apr 04, 2017 10:19 pm

thank you . i will see if i can figure it out .

every newbie needs a little spoon feeding to grow .

ClipArtGuy
Posts: 220
Joined: Wed Aug 19, 2015 4:29 pm

Re: datagrid not saving between launches on android

Post by ClipArtGuy » Tue Apr 04, 2017 10:30 pm

In addition to the scripting conference stacks that Klaus linked to, I would also recommend going through the information at :

http://livecode.byu.edu/indexgeneric.php

I found both this site and the scripting conference stacks to be of immense value when I was just starting out with LiveCode.

Klaus
Posts: 11207
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: datagrid not saving between launches on android

Post by Klaus » Wed Apr 05, 2017 10:49 am

Hi gurusonwheels,
gurusonwheels wrote:thank you . i will see if i can figure it out .
every newbie needs a little spoon feeding to grow .
OK, please come back when problems arise, I have a lot of tiny spoons! :D


Best

Klaus

gurusonwheels
Posts: 31
Joined: Sat Apr 01, 2017 5:15 pm

Re: datagrid not saving between launches on android

Post by gurusonwheels » Fri Apr 07, 2017 1:55 am

works great on my windows system . however when i test on android im not getting the save and reload like happens in windows .

im thinking it some kind of permission problem . maybe its trying to save the file on android somewhere it not aloud .

any tips ?

Klaus
Posts: 11207
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: datagrid not saving between launches on android

Post by Klaus » Fri Apr 07, 2017 10:11 am

Hi Guru,

yes, on mobile (iOS and Android) we are only allowed to write in the apps documents folder!

Same applies to standalones on Mac and Windows! If they are (correctly) installed in the
"Programms X86" (Windows, not sure if that is the correct folder name) or "Applications" (Mac)
folder, we are not allowed to write there if not logged in as ADMIN!

Do this:

Code: Select all

...
## Save content of datagrid to file:
put the dgtext of grp  "your datagrid here" into tVariable

## Create allowed pathname:
put specialdfolderpath("documents") & "/saved_data.text") into tFile
put tVariable into url("file:" & tFile)
...

Code: Select all

...
## Read file on disk and set the content of your datagrid to the content of that file
## First create correct pathname:
put specialdfolderpath("documents") & "/saved_data.text") into tFile

## We are the programmers, so we need to check everything :-)
## No file, no need to progress!
if there is NOT a file tFIle then
  exit to top
end if
put url("file:" & tFile) into tVariable
set the dgtext of grp "your datagrid here" to tVariable
...
Best

Klaus

gurusonwheels
Posts: 31
Joined: Sat Apr 01, 2017 5:15 pm

Re: datagrid not saving between launches on android

Post by gurusonwheels » Fri Apr 07, 2017 12:55 pm

i have tried this by first fixing the extra ) in :

Code: Select all

specialdfolderpath("documents") & "/saved_data.text")
i have also tried changing documents to Documents

still does not work .
wonder if anyone has android saving and opening a file ok ?

Klaus
Posts: 11207
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: datagrid not saving between launches on android

Post by Klaus » Fri Apr 07, 2017 1:05 pm

Sorry, I have a typo (a D too much) in -> specialdfolderpath!

This will do:

Code: Select all

...
specialfolderpath("documents") & "/saved_data.text")
...

gurusonwheels
Posts: 31
Joined: Sat Apr 01, 2017 5:15 pm

Re: datagrid not saving between launches on android

Post by gurusonwheels » Fri Apr 07, 2017 1:33 pm

still not working ..

i have 1 datagrid named "DataGrid"

1 button with this to delete a line

Code: Select all

on mouseUp
   put the dgHilitedLines of group "DataGrid" into theLineNo
   dispatch "deleteline" to group "DataGrid" with  theLineNo
   
## Save content of datagrid to file:
put the dgtext of grp  "DataGrid" into tVariable

## Create allowed pathname:
put specialfolderpath("Documents" & "/saved_data.text") into tFile
put tVariable into url("file:" & tFile)

end mouseUp
i have another button where i can just clear the datagrid

Code: Select all

on mouseUp
    set the dgtext of grp "DataGrid" to empty
end mouseUp
and a final button to test if it will load the file into the datagrid

Code: Select all

on mouseUp
   ## Read file on disk and set the content of your datagrid to the content of that file
## First create correct pathname:
put specialfolderpath("Documents" & "/saved_data.text") into tFile

## We are the programmers, so we need to check everything :-)
## No file, no need to progress!
if there is NOT a file tFIle then
  exit to top
end if
put url("file:" & tFile) into tVariable
set the dgtext of grp "DataGrid" to tVariable

end mouseUp


not sure whats wrong .
i get no errors on the android device .

Klaus
Posts: 11207
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: datagrid not saving between launches on android

Post by Klaus » Fri Apr 07, 2017 1:42 pm

Hm, which of your three scripts does not work?

Please try with -> specialdfolderpath("documents")
No capital D with documents, I think the Android OS is case sensitive just like iOS.

You can also add some more errorchecking:

Code: Select all

...
## Create allowed pathname:
put specialfolderpath("documents") & "/saved_data.text" into tFile
put tVariable into url("file:" & tFile)

## the result is EMPTY on success!
if the result <> EMPTY then
  answer "Error:" && the result
end if
...
Maybe an eventual error will give us a hint.

P.S.
I just saw I left out a neccessary parens ) resp. put it at the wrong place!
It must be:
...
put specialfolderpath("documents") & "/saved_data.text" into tFile
...
Sorry again! Should really proof-read my postings... :oops:

gurusonwheels
Posts: 31
Joined: Sat Apr 01, 2017 5:15 pm

Re: datagrid not saving between launches on android

Post by gurusonwheels » Fri Apr 07, 2017 6:11 pm

got it to partly work . i had to add

Code: Select all

   local tFile
to the beginning of my mouseup handler .

however there is a problem i can seem to solve from the datagrid documentation .

if i clear the datagrid using my button like so :

Code: Select all

set the dgtext of grp "DataGrid" to empty
if i do the following

Code: Select all

on mouseUp
   local tFile
   ## Read file on disk and set the content of your datagrid to the content of that file
## First create correct pathname:
put specialFolderPath("Documents") & "/saved_data.text" into tFile

## We are the programmers, so we need to check everything :-)
## No file, no need to progress!
if there is NOT a file tFIle then
  exit to top
end if
put url("file:" & tFile) into tVariable
set the dgtext of grp "DataGrid" to tVariable


end mouseUp
it loads the data but it loads at the bottom of the data grid with blank spaces in all the rows where i cleared the data .
why does it not load from the Top ?

in other word . if there was 1000 rows of data > then i save > click clear > load data . now there is 1000 blank rows before the loaded data .

Klaus
Posts: 11207
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: datagrid not saving between launches on android

Post by Klaus » Fri Apr 07, 2017 6:28 pm

Hi gurusonwheels,
gurusonwheels wrote:got it to partly work . i had to add

Code: Select all

   local tFile
to the beginning of my mouseup handler.
you have obviously checked "Variable Checking" in the "Edit" menu.
This way you are forced to declare ALL variables you are using!
gurusonwheels wrote:however there is a problem i can seem to solve from the datagrid documentation .

if i clear the datagrid using my button like so :

Code: Select all

set the dgtext of grp "DataGrid" to empty
if i do the following

Code: Select all

on mouseUp
   local tFile
   ## Read file on disk and set the content of your datagrid to the content of that file
   ## First create correct pathname:
   put specialFolderPath("documents") & "/saved_data.text" into tFile

   ## We are the programmers, so we need to check everything :-)
   ## No file, no need to progress!
  if there is NOT a file tFIle then
     exit to top
  end if
  put url("file:" & tFile) into tVariable
  set the dgtext of grp "DataGrid" to tVariable
end mouseUp
it loads the data but it loads at the bottom of the data grid with blank spaces in all the rows where i cleared the data .
why does it not load from the Top ?
in other word if there was 1000 rows of data > then i save > click clear > load data . now there is 1000 blank rows before the loaded data .
hm, never seen thisbefore!? :shock:
Works as exspected on my Mac.

Useful hint: HIT the TAB key while the cursor is in a handler, this way you force LC to format your handler nicely!

Post Reply

Return to “Getting Started with LiveCode - Complete Beginners”