kompiler Member Licensed User Longtime User Nov 6, 2019 #1 I wrote a function that looks for entries and returns a sorted result, but the result is not sorted, why? Tabela is Code: Copy key=LIDamian, value=Damian key=LIAnna, value=Anna key=LITest, value=Test key=MIDamian2, value=Damian2 key=MIAnna2, value=Anna2 key=MITest2, value=Test2 Code Code: Copy Public Sub Find(Key As String) As Map Dim ResultSet1 As ResultSet = SQL1.ExecQuery2("SELECT * FROM Tabela WHERE key LIKE ? ORDER BY value ASC", Array As String(Key)) Dim Map1 As Map Map1.Initialize Do While ResultSet1.NextRow Map1.put(ResultSet1.GetString2(0),ResultSet1.GetString2(1)) Loop Return Map1 End Sub Code: Copy Dim Map1 As Map Map1.Initialize Map1=PreferenceManager1.Find("LI%") For Each KY As String In Map1.Keys Log(KY) Next Log Code: Copy LIDamian LIAnna LITest Last edited: Nov 6, 2019
I wrote a function that looks for entries and returns a sorted result, but the result is not sorted, why? Tabela is Code: Copy key=LIDamian, value=Damian key=LIAnna, value=Anna key=LITest, value=Test key=MIDamian2, value=Damian2 key=MIAnna2, value=Anna2 key=MITest2, value=Test2 Code Code: Copy Public Sub Find(Key As String) As Map Dim ResultSet1 As ResultSet = SQL1.ExecQuery2("SELECT * FROM Tabela WHERE key LIKE ? ORDER BY value ASC", Array As String(Key)) Dim Map1 As Map Map1.Initialize Do While ResultSet1.NextRow Map1.put(ResultSet1.GetString2(0),ResultSet1.GetString2(1)) Loop Return Map1 End Sub Code: Copy Dim Map1 As Map Map1.Initialize Map1=PreferenceManager1.Find("LI%") For Each KY As String In Map1.Keys Log(KY) Next Log Code: Copy LIDamian LIAnna LITest
Erel B4X founder Staff member Licensed User Longtime User Nov 6, 2019 #2 Maps in B4i do not preserve the order. You can use B4XOrderedMap from B4XCollections library instead. Upvote 0
Maps in B4i do not preserve the order. You can use B4XOrderedMap from B4XCollections library instead.