Error getting Array from Map stored in a file

onumad

Member
Licensed User
Longtime User
I can store/restore fine in MyMap, but I can't restore MyArray values with File.ReadMap

B4X:
'Activity module
Sub Process_Globals
End Sub

Sub Globals
End Sub

Sub Activity_Create(FirstTime As Boolean)   
   
   Dim MyMap As Map
   Dim MyArray(2) As Boolean
   
   MyMap.Initialize
   MyArray(0)=True
   MyArray(1)=False

   Log("* Charge")
   For number = 0 To 3      
      MyMap.Put(number, MyArray)
      Log(MyArray(0) & "-" & MyArray(1))
   Next
   
   Log("* Load Directly")
   For number = 0 To 3
      MyArray = MyMap.Get(number)
      Log(MyArray(0) & "-" & MyArray(1))
   Next 
   
   Log("* Write file")
   File.WriteMap(File.DirRootExternal ,"MyMap_deleteme.txt", MyMap)   
   
   Log("* Read file")
   MyMap.Clear
   MyMap = File.ReadMap(File.DirRootExternal ,"MyMap_deleteme.txt")
   
   Log("* Load from readed file")
   For number = 0 To 3
      MyArray = MyMap.Get(number)    '<--------- I'M FAILED!!!!
      Log(MyArray(0) & "-" & MyArray(1))
   Next 
   
End Sub


Sub Activity_Pause (UserClosed As Boolean)
   Activity.Finish
End Sub

Thank you in advance
 

onumad

Member
Licensed User
Longtime User
:sign0104: Solved! with RandomAccessFile lib
B4X:
'Activity module
Sub Process_Globals
End Sub

Sub Globals
End Sub

Sub Activity_Create(FirstTime As Boolean)   
   
   Dim MyMap As Map
   Dim MyArray(2) As String
   Dim fileMap As RandomAccessFile
   MyMap.Initialize
   MyArray(0)="1"
   MyArray(1)="0"

   Log("* Charge")
   For number = 0 To 3      
      MyMap.Put(number, MyArray)
      Log(MyArray(0) & "-" & MyArray(1))
   Next
   
   Log("* Load Directly")
   For number = 0 To 3
      MyArray = MyMap.Get(number)
      Log(MyArray(0) & "-" & MyArray(1))
   Next 
   
   Log("* Write file")
   'File.WriteMap(File.DirRootExternal ,"MyMap_deleteme.txt", MyMap)   
   
   
   
   fileMap.Initialize(File.DirRootExternal ,"MyMap_deleteme.txt", False)
   fileMap.WriteObject(MyMap,False, number)
   fileMap.Close
   
   Log("* Read file")
   MyMap.Clear
   fileMap.Initialize(File.DirRootExternal ,"MyMap_deleteme.txt", True)
   MyMap = fileMap.ReadObject(number)
   fileMap.Close
   
   For number = 0 To 3                  
      MyArray = MyMap.Get(number)    '<--------- I'M FAILED!!!!
      Log(MyArray(0) & "-" & MyArray(1))
   Next 
   
End Sub
 
Upvote 0
Top