Associative Arrays, Lists, Maps

salmander

Active Member
Licensed User
Longtime User
Hello can anyone help me please to solve the following problem?

What do I use to add key => value pair? Lists or Maps?
for e.g. I want to create an array like this;
FS88772 => "Value 1"
FS88773 => "Value 2"
FS88774 => "Value 3"
.
.
FS8877N => "Value N"
and in an InputMultiList I want to display the value1, value2, value3...valueN. Based on what the user selects from the inplutmultilist dialog, I should be able to find the key of those items.

For e.g: if a user selects value 3, value 8 and value 9 from the inputMultiList, i want to fetch the associated Keys of those values.


How can I do this basic4android please?
 

poseidon

Member
Licensed User
Longtime User
re

can be something like :

B4X:
Sub Process_Globals
   'for general Lists use
   Type Element (ItemName As String, Val As String)
End Sub


   Dim LanguagesID As List
   Dim LngItem As Element


      If LanguagesID.IsInitialized=False Then
         LanguagesID.Initialize
      End If 

      LngItem.ItemName = SQLReader.GetColumnName(1)
      LngItem.Val = SQLReader.GetString("recID")
      LanguagesID.Add(LngItem)

//then to retrieve
LngItem = LanguagesID.Get(cmbLanguage.SelectedIndex)
msgbox(LngItem.ItemName,"test")
msgbox(LngItem.Val,"test")
 
Upvote 0

salmander

Active Member
Licensed User
Longtime User
Thank you all for the help.
okay so I am using InputMap to display the options. The map has;
B4X:
Value             Key
FS88772 => "Value 1"
FS88773 => "Value 2"
FS88774 => "Value 3"

how do I get what the user has selected from the dialog? So if the user has selected value 1 and value 3, I also would like to know the FS88772 and FS88774.
 
Upvote 0

poseidon

Member
Licensed User
Longtime User
B4X:
Sub Process_Globals
    'for general Lists use
    Type Element (ItemName As String, Val As String)
    Dim LanguagesID As List
End Sub

//on a buttonAdd_click
    Dim LngItem As Element


        If LanguagesID.IsInitialized=False Then
            LanguagesID.Initialize
        End If 


        LngItem.ItemName = "Value 1"
        LngItem.Val ="FS88772"
        LanguagesID.Add(LngItem)

        LngItem.ItemName = "Value 2"
        LngItem.Val ="FS88773"
        LanguagesID.Add(LngItem)


        LngItem.ItemName = "Value 3"
        LngItem.Val ="FS88774"
        LanguagesID.Add(LngItem)

//on a buttonRead_click
LngItem = LanguagesID.Get(2)
msgbox(LngItem.ItemName,"test")
msgbox(LngItem.Val,"test")

//if you like to find in list you have to make a loop aka LanguagesID.Get(i)
 
Upvote 0

salmander

Active Member
Licensed User
Longtime User
thanks mate.
But it is returning the "value1", "value3"....etc. I want to find their respective values. Like "FS88772", "FS88774"
 
Upvote 0

salmander

Active Member
Licensed User
Longtime User
Thanks again mate. Sorry I think I didn't clearly explain myself. I am using InputMap dialog and the user selects some values and clicks okay. So the returned list only has one value. How can I get the associated key of the chosen values?
 
Upvote 0

poseidon

Member
Licensed User
Longtime User
re

hmmm, InputMap explained by Erel here
B4X:
http://www.b4x.com/forum/basic4android-updates-questions/14041-inputmultilist-help.html#post79431

I hope is clear..
 
Upvote 0
Top