arrayEncode

Anything beyond the basics in using the LiveCode language. Share your handlers, functions and magic here.

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
drOrganized
Posts: 24
Joined: Tue Dec 04, 2007 7:02 pm

arrayEncode

Post by drOrganized » Sun Feb 07, 2010 9:40 pm

I would like to store the content of a data grid in a file. I tried the following without success:

put the dgData of group "test" into pArrayData
open file "Test" for binary write
write arrayEncode(pArrayData) to file "test"
close file "Test"

Nothing is written to the file.

I tried also

open file "Test" for binary read
read from file "Test" until empty
put arrayDecode(it) into pArrayData
close file "Test"
set the dgData of group "test" to pArrayData

I suppose I could convert the array to a variable and then save the variable and vice versa, but I got the impression from the User Dictionary that the code above would work.

Any help much appreciated.

bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 4163
Joined: Sun Jan 07, 2007 9:12 pm

Re: arrayEncode

Post by bn » Sun Feb 07, 2010 10:27 pm

drOrganized,
I did not get your script to work either. I don't know why. But

Code: Select all

   put the dgData of group "DataGrid 1" into pArrayData
   put arrayEncode(pArrayData) into pArrayData
   put specialfolderpath ("desktop") & "/" into aPath
   put "arrayExportTest" after aPath
   put pArrayData into URL ("binfile:" & aPath)
works for me.
I reimported the data into the datagrid and with arrayDecode it works.
regards
Bernd

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10043
Joined: Sat Apr 08, 2006 7:05 am
Contact:

Re: arrayEncode

Post by FourthWorld » Mon Feb 08, 2010 6:21 am

The difference between the working an non-working scripts suggests the issue is in the way the data is read.

I wonder if changing "read until empty" to "read until EOF" would work.
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 4163
Joined: Sun Jan 07, 2007 9:12 pm

Re: arrayEncode

Post by bn » Mon Feb 08, 2010 10:33 am

drOrganized,
here is the script that reads the data and populates the datagrid

Code: Select all

on mouseUp
    put specialfolderpath ("desktop") & "/" into aPath
    put "arrayExportTest" after aPath
    breakpoint
   put url ("binfile:"& aPath) into pArrayData
   put arrayDecode(pArrayData) into pArrayData
   set the dgData of group "DataGrid 1" to pArrayData
end mouseUp
this works for me
regards
Bernd

Post Reply