Maps and retrieving Values

Malky

Active Member
Licensed User
Longtime User
Hi, I have created a db table called diction, but when I try to query it using the maps option, I keep getting NULL values for some reason?
I know there is data in there as I have copied the db to my PC to test it.

B4X:
Sub PopulateDiction(lang As String)
   Dim Cursor1 As Cursor
   Cursor1 = SQL1.ExecQuery("Select id," & lang & " from diction")
   For i = 0 To Cursor1.RowCount - 1
   Cursor1.Position = i
      Dim m As Map
      m.initialize
      
      m.Put("id",m.Get(i))
      m.Put("lang",m.Get(lang))
      DictionList.Put(i,m.Get("lang"))
   Next
End Sub
The 'lang' variable displays as expected, so I can't possibly see an error in the simple SQL query, but getting the data into usable list is the problem. I need to retrieve a word from a list with an integer and a string based on the integer value.

Am I missing something totally obvious?

Malky
 

klaus

Expert
Licensed User
Longtime User
Sorry, but i don't understand what exactly you are trying to do:
I don't undersand this code:
B4X:
Dim m As Map
m.initialize
        
m.Put("id",m.Get(i))
You are trying to get a value from a Map you just initialized?
In your case m.Get(i) = Null

Best regards.
 
Upvote 0

Malky

Active Member
Licensed User
Longtime User
Hi Klaus, I just want to get the id column and the language column, (which could be en, bg,ru, or gr from the diction table which holds the main language translations. I need the row 'id' and ONLY the selected language, say 'en' for the English column into an array, so then I can display the text of any buttons, labels, texts or messages in the selected language throughout the app. i.e.
label1.text = Languages(34) or whatever index number is needed.

It will get worse later as I have more fields in the other tables I need. What have I started? :)

Cheers,

Malky
 
Upvote 0

klaus

Expert
Licensed User
Longtime User
If I have really understoud what you want, I would do it that way:
B4X:
Sub PopulateDiction(lang As String)
    Dim Cursor1 As Cursor
    Cursor1 = SQL1.ExecQuery("SELECT id, lang FROM diction")
    For i = 0 To Cursor1.RowCount - 1
        Cursor1.Position = i
        DictionList.Put(Cursor1.GetLong("id"), Cursor1.GetString("lang"))
    Next
End Sub
I have made multilangage apps with one text file for each langauge and load it in a string array. You could have a look at the NotePad app.
I have used this principle for many years also in VB6.

Best regards.
 
Upvote 0

Malky

Active Member
Licensed User
Longtime User
Hi Klaus you make it look so easy!!

How do I access the word in dictionlist though?

I am trying to test it with ToastMessageShow(DictionList(2), True) and getting an error as expected. Sure I saw something earlier in posts about this, but been through so many.

Incidentally, I had to change the Cursor1.GetString("lang") part to Cursor1.GetString(lang) without the quotes as it is a variable.

Cheers, and thank you very much again. Been in a rush as I have to go to bed for work tomorrow.

Malky
 
Upvote 0
Top