VB Migration Partner

KNOWLEDGE BASE - Language


Previous | Index | Next 

[PRB] The Scripting.Dictionary object doesn’t work with Enum keys

Under VB6 enumerated values are nothing but aliases for 32-bit integer; conversely, under VB.NET an enumerated value is a first-class citizen. VB.NET languages allow implicit conversions between enumerated values and integers, therefore you usually don’t have to account for this minor difference, but there are a few exceptions, for example when you use an enum value as the key for a Scripting.Dictionary object:

Dim dict As New Dictionary

Sub Test(ByVal key As MyEnumType)
	Debug.Print dict(key) = dict(CInt(key))
End Sub

Under VB6 the Debug.Print statement displays True, whereas under VB.NET it display False; as you might guess, the reason is that – when used as keys for the dictionary – the enumerated value and its integer equivalent are considered as different values and therefore reference different dictionary elements.

We could easily modify the VB6Dictionary class to account for this minor difference, yet we decided not to, because it would add a major overhead each time any dictionary element is read or written to, and such overhead would be hardly justified given that it is a very rare case. (In many years only a single customer report this erratic behavior.)

As a result, if you use enumerated values as keys for a Dictionary object, ensure that you use them in a consistent way. In other words, you should either always use enumerated values or their corresponding integer values, but you should never mix them in the same project.

Previous | Index | Next 




Follow Francesco Balena on VB6 migration’s group on

LinkedIn





Read Microsoft Corp’s official case study of a VB6 conversion using VB Migration Partner.




Code Architects and its partners offers remote and onsite migration services.

More details




Subscribe to our free newsletter for useful VB6 migration tips and techniques.

newsletter



To learn more about your VB6 applications, run VB6 Analyzer on your source code and send us the generated text file. You will receive a detailed report about your VB6 applications and how VB Migration Partner can help you to quickly and effectively migrate it to .NET.

Get free advice



A fully-working, time-limited Trial Edition of VB Migration Partner allows you to test it against your actual code

Get the Trial




The price of VB Migration Partner depends on the size of the VB6 application, the type of license, and other factors

Request a quote




Migrating a VB6 application in 10 easy steps

Comparing VB Migration Partner with Upgrade Wizard

Migration tools: Feature Comparison Table

All whitepapers