Saturday, February 4, 2017

Pass an Variant Array from VB6 to VB.net

There is no variant type in vb.net.
If you have an Variant array declared in VB6 and you are trying to pass this to VB.net, you would need to pass variant as object .net and declare an array and loop thru each item from the passed object and add it to array.

Example:

My VB6 code:
 Dim variantArray As Variant
 variantArray = Empty  
 ReDim variantArray(1)
 variantArray(0) = "C:\pic1.jpg"
 variantArray(1) = "C:\pic2.jpg"

So now in VB.net, you can either pass this parameter to a function or a property of an object of .net class. See code below as property:
 Private _stringArray As String()  
 Public Property StringArray As Object
     Get  
         Return _stringArray  
     End Get  
     Set(value As Object)  
       If Not value Is Nothing Then  
           ReDim _stringArray(value.length - 1)  
           For i As Int16 = 0 To value.length - 1  
               _stringArray(i) = value(i)  
           Next  
       End If  
     End Set  
 End Property