Previous | Index | Next 

[PRB] The IsArray method returns False with unitialized array stored in Object variables

The VB6 IsArray method is capable to recognize arrays that are stored inside a Variant, as the following code illustrates:

        Dim arr() As Double
        Dim v As Variant
        v = arr
        Debug.Print IsArray(arr) & ", " & IsArray(v)      ' displays "True, True"

The VB.NET IsArray method differs from the VB6 version in that it fails to recognize uninitialized arrays, as the corresponding version of previous code demonstrates:

        Dim arr() As Double
        Dim v As Object
        v = arr
        Debug.Print IsArray(arr) & ", " & IsArray(v)      ' displays "False, False"

This reason for this difference is that an uninitialized VB.NET array is Nothing, hence the IsArray method can’t discern it from an unitialized (non-array) object. VB Migration Partner translates the IsArray method to the special IsArray6 method, which at least recognizes arrays that are not stored inside an object:

        Dim arr() As Double
        Dim v As Object
        v = arr
        Debug.Print IsArray6(arr) & ", " & IsArray6(v)     ' displays "True, False"

The only way to completely solve this problem is to use a ChangeType pragma that forces the conversion of Variant variables into the special VB6Variant type:

        '## ChangeType Variant, VB6Variant

 

Previous | Index | Next