Solved

VB6 Variant (Array) to VB.NET Array

Posted on 2004-09-29
5
1,374 Views
Last Modified: 2008-02-01
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.
0
Comment
Question by:robert_83
5 Comments
 
LVL 18

Accepted Solution

by:
armoghan earned 100 total points
ID: 12179294
Instead of making String array make object array
0
 
LVL 3

Assisted Solution

by:Arundel_Castle
Arundel_Castle earned 100 total points
ID: 12179558
Try it without an explict cast. Then cast the strings beneath it. My resoning is that object() has no knowledge of variant and you have to cast .Net types to object. The implict cast might trigger something else.

Dim obj() As Object

obj = old.Method()
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
I need help converting a bitmap to an image in VB.Net 1 44
No Data for DropDown List 2 28
Help with error in Query 2 31
SSRS 2016 Rendering HTML tables 3 29
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

837 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question