Andrew (Digitwell) Well-Known Member Licensed User Longtime User Jan 11, 2018 #1 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
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
DonManfred Expert Licensed User Longtime User Jan 11, 2018 #2 Andrew (Digitwell) said: Is this expected behavior with maps? Click to expand... 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...
Andrew (Digitwell) said: Is this expected behavior with maps? Click to expand... 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...
Andrew (Digitwell) Well-Known Member Licensed User Longtime User Jan 11, 2018 #3 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
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
DonManfred Expert Licensed User Longtime User Jan 11, 2018 #4 Code: Copy sub mycheckingsub(in as Map) As Int dim value as int = in.get("idTeam") return value endsub you can write a small helper sub which cast a Object to a int and return the int.... Code: Copy mycheckingsub(tm.get("idTeam")) = mycheckingsub(chktm.get("idTeam"))
Code: Copy sub mycheckingsub(in as Map) As Int dim value as int = in.get("idTeam") return value endsub you can write a small helper sub which cast a Object to a int and return the int.... Code: Copy mycheckingsub(tm.get("idTeam")) = mycheckingsub(chktm.get("idTeam"))
Andrew (Digitwell) Well-Known Member Licensed User Longtime User Jan 11, 2018 #5 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
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
DonManfred Expert Licensed User Longtime User Jan 11, 2018 #6 Andrew (Digitwell) said: wouldn't the code be Click to expand... 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...
Andrew (Digitwell) said: wouldn't the code be Click to expand... 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...