Link to home
Start Free TrialLog in
Avatar of robert_83
robert_83

asked on

VB6 Variant (Array) to VB.NET Array

Hi,

I have a VB6 method that returns an array of strings as a Variant.

When I try and convert this to a VB.NET string array, I receive the cast error. So, to get around this I do the following:

Dim a As Array = CTYPE(old.Method(), Array)

This does not throw an exception, so I therefore assume that the VB6 method is indeed returning an array object. However, I cannot cast this to a string array, even though each element in the Array 'a' is of type string.

Also,

Dim obj() As Object = CTYPE(old.Method(), Object()) produces the same error.

So, I cannot cast the returned Variant to an Object() / String(), but I can cast it to Array.

Furthermore, in VB.NET I would simply do,

Private Function a() As Object
  Dim str(1) As String
  Return str
End Function

Dim newStr() As String = CTYPE(a(), String())

Thanks.
ASKER CERTIFIED SOLUTION
Avatar of armoghan
armoghan
Flag of Pakistan image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial