Cannot read and decode array from file (solved)

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

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
mrcoollion
Posts: 709
Joined: Thu Sep 11, 2014 1:49 pm
Location: The Netherlands

Cannot read and decode array from file (solved)

Post by mrcoollion » Sun Jul 01, 2018 10:19 am

I am really starting to feel like a beginner again... :oops:

I cannot seem to write an array into a file and then read it back into an array.
This is my code for saving the array which works because in notepad I see the data.

Code: Select all

-------------------------
   // Encode Aray with language data with arrayEncode function to convert an array into a string  and save file
   put field "ApplicationName" into Array_LangFile["application"] 
   open file tFile for write 
   write arrayEncode(Array_LangFile) to file tFile
   close file tFile
   // end make file
   -------------------------
With this code I try to read the data back into an array. I get the data but I am afraid it is not in a format that arrayDecode can use because 'put arrayDecode(tEncodedArray) into Array_LangFile' does not do anything.

Code: Select all

// Read data from file tFile
   -------------------------
   read from file tFile until EOF
   if it is empty 
   then
      answer "There is no data in this file!"
      close file tFile
      exit mouseUp
   end if
   put it into tEncodedArray
   close file tFile
   put arrayDecode(tEncodedArray) into Array_LangFile
   put Array_LangFile["application"] into tApplicationName
   -----------------------
Last edited by mrcoollion on Sun Jul 01, 2018 10:41 am, edited 1 time in total.

mrcoollion
Posts: 709
Joined: Thu Sep 11, 2014 1:49 pm
Location: The Netherlands

Re: Cannot read and decode array from file

Post by mrcoollion » Sun Jul 01, 2018 10:41 am

Sorry .. got it to work.. needed to use binfile ... see code below for those interested. :shock:

Save the array into a file

Code: Select all

 --------------------------
      put "binfile:"&tFile into tBinPathFile
      put arrayEncode(Array_File) into URL tBinPathFile
 -------------------------
read the array from a file

Code: Select all

 --------------------------
      put "binfile:"&tFile into tBinPathFile
      put URL tBinPathFile into tEncodedArray
      put arrayDecode(tEncodedArray) into Array_File
 -------------------------

Post Reply

Return to “Talking LiveCode”