Page 1 of 1

Cannot read and decode array from file (solved)

Posted: Sun Jul 01, 2018 10:19 am
by mrcoollion
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
   -----------------------

Re: Cannot read and decode array from file

Posted: Sun Jul 01, 2018 10:41 am
by mrcoollion
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
 -------------------------