

For single values, wrap in Array()"Įrr.Description = "That value cannot be found in the map, ensure it is of the same data type as the original keys" must have the same length)"Ĭase tsNotIterableErrorĮrr.Description = "One of iterableA and iterableB is not iterable. Select Case errNum 'overwrite description with custom error text - case else would be keep default and rethrow errorĬase gtMappingErrors.mismatchedLengthErrorĮrr.Description = "iterableA and iterableB must have a 1 to 1 correspondence (i.e. Private Sub raiseError(ByVal errNum As gtMappingErrors, Optional ByVal sourceMethod As String = vbNullString) If (aValue) Then 'without this check, aValue is silently added to the dictionary which is probably not what we want Public Property Get BfromA(ByVal aValue As Variant) As VariantĬonst errorSourceName As String = "BfromA" 'CHECK RaiseError valueNotInMapError, errorSourceName Public Property Get AfromB(ByVal bValue As Variant) As VariantĬonst errorSourceName As String = "AfromB" 'CHECK Private Property Get collectionFromIterable(ByVal iterable As Variant) As Collectionĭim result As New Collection 'auto-instantiate so we always return a valid collection, even if no members Resume 'comment out error raising and break here to debug RaiseError setsNotIterableError, errorSourceName

If aValues.Count bValues.Count Then raiseError mismatchedLengthError, errorSourceNameĬonst objectNotIterableError As Long = 438 'object does not support methodĬonst typeNotIterableError As Long = 13 'type mismatchĬase objectNotIterableError, typeNotIterableError Set bValues = collectionFromIterable(iterableB) Set aValues = collectionFromIterable(iterableA) 'need data to be in some form that can be indexed, as For.Each only operates on one at a time Public Sub growMapping(ByVal iterableA As Variant, ByVal iterableB As Variant)Ĭonst errorSourceName As String = "growMapping" 'CHECK iterableA and iterableB should be ordered iterables of equal length. Public Function Create(ByVal iterableA As Variant, ByVal iterableB As Variant) As TwoWayMappingįriend Property Get Self() As TwoWayMappingĮnd key - value pairs mapping items from A to B (and vice-versa) based on each item's index within the collection. = 1 'set to a different value for each class in a project * Does RD provide a way to annotate references? Predeclared Class: TwoWayMapping IndexedDefaultMemberAccess: It's fine for collections I thinkĪtoB As New Dictionary 'Use dictionary as this allows any item as key, not just strings as with collectionsītoA As New Dictionary 'Auto-instantiate so we don't need growMapping to worry about whether the map was initialised My approach is to wrap two Scripting.Dictionaries to create the reversible pairing - be sure to reference Microsoft Scripting Runtime ( scrrun.dll) * This is because I want to be able to switch between corresponding members of 2 enums with different values, or between an enum and the text representation of its members. I've created a class that creates key->value pairs but also value->key pairs - i.e.
