VB Migration Partner

KNOWLEDGE BASE - Language


Previous | Index | Next 

[PRB] Arrays held in Variant and Object variables are converted in a special way

Under VB6 it is legal to apply the ReDim, ReDim Preserve, and Erase keywords to a scalar (non-array) Variant variable:

        Dim arr() As Double
        Dim v As Variant
        v = arr
        ReDim v(20) As Double
        v(10) = 123

VB Migration Partner supports this syntax and generates a call to the Redim6 or RedimPreserve6 helper methods, defined in the support library. These two methods work exactly like the VB6 keywords, except for one detail: if the Object or VB6Variant variable holds an array of UDTs (i.e. .NET structures), then the structure might not be initialized correctly. For example, if the UDT contains fixed-length strings, auto-instantiating (As New) objects, or static arrays, then those elements won’t be initialized to their correct value.

The only workaround for this problem is that you manually initialize each element of the array after performing the Redim6 method (and the RedimPreserve6 method, if the array has been extended)

        ' in this VB.NET example, MyUDT is a structure that must be initialized
        Dim arr() As MyUDT
        Dim v As Object
        v = arr
        ReDim6(v, 1, 20)
        ' initialize each array element, using the extra constructor that
        ' has been generated by VB Migration Partner
        For i As Integer = 0 To 20
            v(i) = New MyUDT(False)
        Next
        v(10) = 123

A similar problem occurs when the Erase keyword is applied to an Object or VB6Variant variable that holds a static array. In this case it is recommended that you manually re-initialize each element of the array.

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