How to write an array to file using map object?

Pantelis

Member
Licensed User
Longtime User
Hi guys
Im trying to write an array to a file using map object and to load the array back but it doesn't work. I use any help i find in the forrum but nothing. :BangHead:

B4X:
Sub Process_Globals
   Dim Array1(2,2) As Int
   Dim Array2(2,2) As Int
   Dim MyMap As Map
End Sub

Sub Activity_Create(FirstTime As Boolean)
   MyMap.Initialize
   Dim i As Int
   Dim j As Int
   
   'Give some value to array1
   For i = 0 To 1
      For j = 0 To 1
         Array1(i,j) = i
      Next
   Next

   'Put the array to Map
   MyMap.Put("1",Array1)
   
   'Save the map to a file
   File.WriteMap(File.DirInternal,"Data.tbl",MyMap)   
   
   If File.Exists(File.DirInternal,"Data.tbl") Then
      'Load the map from the file
      MyMap = File.ReadMap(File.DirInternal,"Data.tbl")      
   Else
      Msgbox ("File does not exist","Some Title")
   End If
   
   'Get the Array from map to another array
   Array2 = MyMap.Get("1")
   
   Msgbox( Array2(0,0)&Array2(0,1)&Array2(1,0)&Array2(1,1),"SomeTitle")
   
End Sub
 
Top