Android Question Implicit string to integer question

johnf2013

Member
Licensed User
Longtime User
colorMap keys are color codes and the values are color strings.

The following code does not work;

B4X:
colorSettings.AddList2("Background","Plot background",colorMap.Get(prefManager.GetString("Background")),defGridBkgColor,"",colorMap)

This code does work;

B4X:
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?
 

johnf2013

Member
Licensed User
Longtime User
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
Top