Bug? Integer type casting and maps

Andrew (Digitwell)

Well-Known Member
Licensed User
Longtime User
I have various items in a map some of them are ints.

I have found that if you compare 2 items as follows the results do not always work as expected.
Each of the following maps tm and chktm have a key value pair with a name of idTeam and a value of type int.

Code: Copy
   if (tm.get("idTeam") = chktm.get("idTeam")) then
      Log("Match found") ' Match is sometimes found but not always
    end if

bit this always works

Code: Copy
   private v1,v2 as int
   v1 = tm.get("idTeam")
   v2 = chktm.get("idTeam")
   if (v1 = v2) then
      Log("Match found") ' This always works as expected
    end if

Is this expected behavior with maps?
I'm having to go through all my code and update comparisons.

Thanks
Andrew
 
Is this expected behavior with maps?
It sompares one OBJECT with another OBJECT (the map does contains Objects.)
It is expected i would say.
In case
Code: Copy
tm.get("idTeam") = chktm.get("idTeam")
does work then the values inside the tm Object and the chktm Object (the value inside) are the same objects you added...
 
Fair enough, if it is the expected behavior.

It would be great if you could write

Code: Copy
(int)tm.get("idTeam") = (int)chktm.get("idTeam")

or some such to force the casting rather than doing the assignments, but now I know, I will code accordingly.

Cheers

Andrew
 
Good idea! that feels a bit neater

wouldn't the code be

Code: Copy
sub mycheckingsub(in as Object) As Int
dim value as int = in
return value
end sub
 
wouldn't the code be
then you must send the value from the Object inside the call. Does work too. I suggest to use the map and also give the value you want to return from the map.

Depends on your needs/what is more confortable for you...
 
Back
Top