johnf2013 Member Licensed User Longtime User Jan 4, 2018 #1 colorMap keys are color codes and the values are color strings. The following code does not work; Code: Copy colorSettings.AddList2("Background","Plot background",colorMap.Get(prefManager.GetString("Background")),defGridBkgColor,"",colorMap) This code does work; Code: Copy Dim x As Int x = prefManager.GetString("Background") colorSettings.AddList2("Background","Plot background",colorMap.Get(x),defGridBkgColor,"",colorMap) In the first case I would have expected an implicit conversion from string to integer in the .Get method. In practice the conversion fails and so the key is not found. In the second case I force the implicit conversion from string to integer and the key lookup succeeds. Why would this be so?
colorMap keys are color codes and the values are color strings. The following code does not work; Code: Copy colorSettings.AddList2("Background","Plot background",colorMap.Get(prefManager.GetString("Background")),defGridBkgColor,"",colorMap) This code does work; Code: Copy Dim x As Int x = prefManager.GetString("Background") colorSettings.AddList2("Background","Plot background",colorMap.Get(x),defGridBkgColor,"",colorMap) In the first case I would have expected an implicit conversion from string to integer in the .Get method. In practice the conversion fails and so the key is not found. In the second case I force the implicit conversion from string to integer and the key lookup succeeds. Why would this be so?
Erel B4X founder Staff member Licensed User Longtime User Jan 4, 2018 #2 Map.Get method expects an Object. The compiler cannot know that your keys are integers. Upvote 0
johnf2013 Member Licensed User Longtime User Jan 4, 2018 #3 Ok, makes sense. I am a C/C++ programmer making a foray into Basic. I would just cast it. What do I do in Basic? Upvote 0
Ok, makes sense. I am a C/C++ programmer making a foray into Basic. I would just cast it. What do I do in Basic?
Erel B4X founder Staff member Licensed User Longtime User Jan 4, 2018 #4 johnf2013 said: What do I do in Basic? Click to expand... The programming language is named B4X. You cast it with: Code: Copy Dim x As Int = prefManager.GetString("Background") colorSettings.AddList2("Background","Plot background",colorMap.Get(x),defGridBkgColor,"",colorMap) Upvote 0
johnf2013 said: What do I do in Basic? Click to expand... The programming language is named B4X. You cast it with: Code: Copy Dim x As Int = prefManager.GetString("Background") colorSettings.AddList2("Background","Plot background",colorMap.Get(x),defGridBkgColor,"",colorMap)
johnf2013 Member Licensed User Longtime User Jan 4, 2018 #5 Ok thanks for your help. B4X it is from now on!!! Upvote 0