I have read and read and written until i am confused
All i am trying to do is write a couple of values and then re-read them
The code is as follows
B4X:
Sub Activity_Resume
Dim m As Map
m.Initialize
m.Put("PageNumber","")
m.Put("CatNum","")
If File.Exists(File.DirInternal, "Settings.txt") Then
m = File.ReadMap2(File.DirInternal, "Settings.txt", m)
End If
Log(PageNumber)
Log(CatNum)
end sub
Sub Activity_Pause (UserClosed As Boolean)
Dim m As Map
m.Initialize
m.Put("PageNumber", PageNumber)
m.Put("CatNum", PageNumber)
File.WriteMap(File.DirInternal, "Settings.txt",m)
End Sub
So where am i going wrong? I have tried many variations of assigning values etc. But i just am not getting it
Sub Activity_Resume
Dim m As Map
m.Initialize
If File.Exists(File.DirInternal, "Settings.txt") Then
m = File.ReadMap(File.DirInternal, "Settings.txt")
[COLOR=red]PageNumber = m.Get("PageNumber")[/COLOR]
[COLOR=red] CatNum = m.Get("CatNum")[/COLOR]
End If
Log(PageNumber)
Log(CatNum)
End sub
Sub Activity_Pause (UserClosed As Boolean)
Dim m As Map
m.Initialize
m.Put("PageNumber", PageNumber)
m.Put("CatNum", [COLOR=red]CatNum[/COLOR])
File.WriteMap(File.DirInternal, "Settings.txt",m)
End Sub
You set the same value to the two different entries.
You must set the map entries to the variables with m.Get.
You could also save the two values in a text file and read them back instead of using the maps.
Yes that is true but i want to learn how to use the map syntax correctly
The problem was that I was unable to save values when moving between activities. The values were being wiped out even thought they were transfered to the main module. So i wAs looking for alternate solutions.
Thanks for the help Klaus, The changed code now works:icon_clap:
The problem was that I was unable to save values when moving between activities. The values were being wiped out even thought they were transfered to the main module. So i wAs looking for alternate solutions.
If you declare the two variables in Sub Process_Globals their content will be maintained when you swap activities.
In that case, you need to save the values in a file only if you need the values of the last run.