stefanoa Active Member Licensed User Longtime User Aug 5, 2012 #1 i have a map "m" filled and then i compile another map "filesMap" with some elements from first map: B4X: Expand Collapse Copy For i = 0 To (m.Size / 9) - 1 filesMap.put( m.Get("ID"), m.Get("Title")) ... next with this control it's all ok!: B4X: Expand Collapse Copy Dim i As Int Log("filesMap.Size:" & filesMap.Size) For i = 0 To filesMap.Size - 1 Log("Key:" & filesMap.GetKeyAt(i) & " - " & "Value:" & filesMap.GetValueAt(i)) Next and the result is (for example): Key:33297 - Value:Everybody's Broken Key:33290 - Value:Lost Highway but if i do: B4X: Expand Collapse Copy Msgbox(filesMap.get(33297), "GetField") or Msgbox(filesMap.get("33297"), "GetField") the result is NULL !!! why?? :sign0085: Last edited: Aug 5, 2012
i have a map "m" filled and then i compile another map "filesMap" with some elements from first map: B4X: Expand Collapse Copy For i = 0 To (m.Size / 9) - 1 filesMap.put( m.Get("ID"), m.Get("Title")) ... next with this control it's all ok!: B4X: Expand Collapse Copy Dim i As Int Log("filesMap.Size:" & filesMap.Size) For i = 0 To filesMap.Size - 1 Log("Key:" & filesMap.GetKeyAt(i) & " - " & "Value:" & filesMap.GetValueAt(i)) Next and the result is (for example): Key:33297 - Value:Everybody's Broken Key:33290 - Value:Lost Highway but if i do: B4X: Expand Collapse Copy Msgbox(filesMap.get(33297), "GetField") or Msgbox(filesMap.get("33297"), "GetField") the result is NULL !!! why?? :sign0085:
margret Well-Known Member Licensed User Longtime User Aug 5, 2012 #2 You have m.size / 9. this will result in a non int variable depending on the value of m.size. You should do this before the loop and convert the answer to an int if it is not. Upvote 0
You have m.size / 9. this will result in a non int variable depending on the value of m.size. You should do this before the loop and convert the answer to an int if it is not.
stefanoa Active Member Licensed User Longtime User Aug 5, 2012 #3 m.size is multiple of 9 but however variable "i" is always int, because start at 0, with step 1 and finish at (m.size /9) correction: in the 1' code is: filesMap.put( m.Get("ID"), m.Get("Title")) PS: in LOG it's all ok: in the example: Key:33297 - Value:Everybody's Broken but the "get" return Value=NULL ! Last edited: Aug 5, 2012 Upvote 0
m.size is multiple of 9 but however variable "i" is always int, because start at 0, with step 1 and finish at (m.size /9) correction: in the 1' code is: filesMap.put( m.Get("ID"), m.Get("Title")) PS: in LOG it's all ok: in the example: Key:33297 - Value:Everybody's Broken but the "get" return Value=NULL !
margret Well-Known Member Licensed User Longtime User Aug 5, 2012 #4 Try your MsgBox() with filesMap.ContainsKey(yourkeyhere) and see if it returns a result. Upvote 0
stefanoa Active Member Licensed User Longtime User Aug 5, 2012 #5 containskey it's always "false" B4X: Expand Collapse Copy For i = 0 To filesMap.Size - 1 Log("Key:" & filesMap.GetKeyAt(i) & " - " & "Value:" & filesMap.GetValueAt(i)) Next Msgbox(filesMap.ContainsKey(33297) , "") or Msgbox(filesMap.ContainsKey("33297") , "") for next >>> Key:33297 - Value:Everybody's Broken ContainsKey >>> is always false Upvote 0
containskey it's always "false" B4X: Expand Collapse Copy For i = 0 To filesMap.Size - 1 Log("Key:" & filesMap.GetKeyAt(i) & " - " & "Value:" & filesMap.GetValueAt(i)) Next Msgbox(filesMap.ContainsKey(33297) , "") or Msgbox(filesMap.ContainsKey("33297") , "") for next >>> Key:33297 - Value:Everybody's Broken ContainsKey >>> is always false
margret Well-Known Member Licensed User Longtime User Aug 5, 2012 #6 OK, in your loop that shows the key 33297, also log the length of it to the log. It should be 5. Maybe there is a hidden character, etc. So see what the logged length is. Upvote 0
OK, in your loop that shows the key 33297, also log the length of it to the log. It should be 5. Maybe there is a hidden character, etc. So see what the logged length is.
stefanoa Active Member Licensed User Longtime User Aug 5, 2012 #7 ok..I solved it by putting ID to a string variable: B4X: Expand Collapse Copy Dim x As String x=m.Get("ID" & i) filesMap.put( x,m.Get("Title" & i)) ... and then, to retrieve the value: B4X: Expand Collapse Copy Dim x As String x=IDx '--- IDx it's a INT and contain ID value Msgbox(filesMap.get(x) , "value") thanks for support! Upvote 0
ok..I solved it by putting ID to a string variable: B4X: Expand Collapse Copy Dim x As String x=m.Get("ID" & i) filesMap.put( x,m.Get("Title" & i)) ... and then, to retrieve the value: B4X: Expand Collapse Copy Dim x As String x=IDx '--- IDx it's a INT and contain ID value Msgbox(filesMap.get(x) , "value") thanks for support!
margret Well-Known Member Licensed User Longtime User Aug 5, 2012 #8 Great, glad you got it!! Upvote 0
C CharlesIPTI Active Member Licensed User Longtime User Aug 23, 2012 #9 Map get Or GetValueAt Personally Don't Like Map.Get its all very convoluted Attached Project... Hope it helps someone Attachments Small Map Kraizness.zip Small Map Kraizness.zip 5.7 KB · Views: 315 Upvote 0
Map get Or GetValueAt Personally Don't Like Map.Get its all very convoluted Attached Project... Hope it helps someone
mr23 Active Member Licensed User Longtime User Aug 9, 2015 #10 +1. Had code with .Get using an Int, used to work, just had to change it to String, and now its back to working. Tilters: Sufficient context. Get doesn't behave the same with Int as String. Provided solution without having to Open a project. Last edited: Aug 9, 2015 Upvote 0
+1. Had code with .Get using an Int, used to work, just had to change it to String, and now its back to working. Tilters: Sufficient context. Get doesn't behave the same with Int as String. Provided solution without having to Open a project.
DonManfred Expert Licensed User Longtime User Aug 9, 2015 #11 This is an OLD thread! Please start a new thread providing much more informations on what you did, what you expected and what you got. But do this in a new thread Upvote 0
This is an OLD thread! Please start a new thread providing much more informations on what you did, what you expected and what you got. But do this in a new thread