using text mappings

merlin2049er

Well-Known Member
Licensed User
Longtime User
Hi, I've got 4 buttons in my app, that I've mapped to a text file with keys.

On the designer the buttons are laid out like this...

[ INPUT 1]
[ INPUT 2]
[ INPUT 3]
[ INPUT 4]

When I read the mapping from the txt file, the inputs are backwards.

[ INPUT 4]
[ INPUT 3]
[ INPUT 2]
[ INPUT 1]

I tried a swapping the mappings, to no avail.
What did I do wrong? lol.
 

merlin2049er

Well-Known Member
Licensed User
Longtime User
Ok, here it is; the code to assign the buttons from the text file

B4X:
'Again we are Not initializing the Map.
   'assign button text from file
    Map1 = File.ReadMap(File.DirRootExternal, "button.txt")
    Button1.Text = Map1.GetValueAt(0)
    Button2.Text = Map1.GetValueAt(1)
    Button3.Text = Map1.GetValueAt(2)
    Button4.Text = Map1.GetValueAt(3)

The code I use to write to the file...

B4X:
'update mapped Button In saved File
Dim Map1 As Map
Map1.Initialize
Map1.Put(0,Button1.Text)
Map1.Put(1,Button2.Text)
Map1.Put(2,Button3.Text)
Map1.Put(3,Button4.Text)
File.WriteMap(File.DirRootExternal, "button.txt", Map1)

Oh, and the code I use to check to see if the file exists... doesn't seem to work on virtual machine? (I tried both True and False here...)

B4X:
'create file first time if it doesn't exist  -- not working -- fix it
   If File.Exists(File.DirDefaultExternal,"button.txt") = True Then
   Map1.Initialize
   Map1.Put(0,Button1.Text )
   Map1.Put(1,Button2.Text )
        Map1.Put(2,Button3.Text )
   Map1.Put(3,Button4.Text )
   File.WriteMap(File.DirRootExternal, "button.txt", Map1)
   End If

Thanks,
Joe
 
Last edited:
Upvote 0

merlin2049er

Well-Known Member
Licensed User
Longtime User
I guess the order isn't entirely important. Just like to keep things in order.

I should start working on the bluetooth section of my app.
 
Last edited:
Upvote 0
Top