D danvica Member Licensed User Longtime User Aug 28, 2011 #1 This code doesn't work: Code: Copy dim m as map dim i,Val as int m=File.ReadMap(File.DirInternal,"myfile.ini") Val=5 for i=0 to m.size-1 if m.ContainsKey(Val)=false then '(Always return false) .... end if next This works: Code: Copy dim m as map dim i,Val as int dim TempVal as string m=File.ReadMap(File.DirInternal,"myfile.ini") Val=5 TempVal=Val for i=0 to m.size-1 if m.ContainsKey(TempVal)=false then 'Works correctly .... end if next I'm still a newbie and maybe I shouldn't call it bug... if you have other explanation please let me know.
This code doesn't work: Code: Copy dim m as map dim i,Val as int m=File.ReadMap(File.DirInternal,"myfile.ini") Val=5 for i=0 to m.size-1 if m.ContainsKey(Val)=false then '(Always return false) .... end if next This works: Code: Copy dim m as map dim i,Val as int dim TempVal as string m=File.ReadMap(File.DirInternal,"myfile.ini") Val=5 TempVal=Val for i=0 to m.size-1 if m.ContainsKey(TempVal)=false then 'Works correctly .... end if next I'm still a newbie and maybe I shouldn't call it bug... if you have other explanation please let me know.
M magalt Member Licensed User Longtime User Aug 28, 2011 #2 It is not a bug. The documentation of the ContainsKey (member of Map) say: ContainsKey (Key As Object) As Boolean Tests whether there is an item with the given key. Example: If Map.ContainsKey("some key") Then ... Marco
It is not a bug. The documentation of the ContainsKey (member of Map) say: ContainsKey (Key As Object) As Boolean Tests whether there is an item with the given key. Example: If Map.ContainsKey("some key") Then ... Marco
agraham Expert Licensed User Longtime User Aug 28, 2011 #3 Map.ContainsKey is not expected to do any type casting. A Map can hold any type of object as both keys and values so you must give it the correct type of object for it to work as expected. In your case ReadMap populates the Map with Strings as both keys and values so you must pass a String type to ContainsKey.
Map.ContainsKey is not expected to do any type casting. A Map can hold any type of object as both keys and values so you must give it the correct type of object for it to work as expected. In your case ReadMap populates the Map with Strings as both keys and values so you must pass a String type to ContainsKey.
D danvica Member Licensed User Longtime User Aug 29, 2011 #4 Ok. I still have to better understand when the compiler decides to cast something. I'm used to C for microcontroller that gives you no help at all... Next times it's better to use discussion forum...:sign0089: Thanks for you patience...
Ok. I still have to better understand when the compiler decides to cast something. I'm used to C for microcontroller that gives you no help at all... Next times it's better to use discussion forum...:sign0089: Thanks for you patience...