Using two integers for one value in a dictionary

How do I use two variables in a dictionary, to get one value. For example d.Value(2,7) = true. I have tried d.Value(Array(2,7)) = true, but that does not seem to work for me, thanks.

use PAIR

Thanks

There’s several ways
Pairs can represent two values
However if you want to know IF a certain pair already exists in the dictionary you may run into trouble
This little bit of code illustrates the issue

[code] dim d as new dictionary

d.value( new Pair(1,2) ) = 123

if d.hasKey( new Pair(1,2) ) then
break
else
break

end if
[/code]
While there IS a pair that holds the VALUE (1,2) thats is NOT what is used as the key in the dictionary - its basically the object reference and the two in this little bit of code are different - so the “HasKey” check fails

What you might need to do or want to do is use a key that is based on the value
Something like the SparseArray class I wrote years ago - see http://www.great-white-software.com/REALbasic_Code.html
It uses a string as the key something like the following

 dim d as new dictionary
  
  d.value( str(1)+":"+str(2) ) = 123
  
  if d.hasKey( str(1)+":"+str(2) ) then
    break
  else
     break
    
  end if

and this WILL find that the key “1:2” exists

If one defines a structure of two ints, I assume using that as the key would work

  • Karen

[quote=54525:@Karen Atkocius]If one defines a structure of two ints, I assume using that as the key would work
[/quote]
Not sure what the issue is but it doesn’t seem to

Sounds like a bug!

  • Karen

I don’t think so. Using a Structure would have the same issues as using a class. Unless it’s the exact same structure, it won’t match, even though the contents do. You’d have to use the StringValue as the key.