Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

VB6 Variant (Array) to VB.NET Array

Posted on 2004-09-29
5
Medium Priority
?
1,421 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
5 Comments
 
LVL 18

Accepted Solution

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

Assisted Solution

by:Arundel_Castle
Arundel_Castle earned 400 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

Article by: jpaulino
XML Literals are a great way to handle XML files and the community doesn’t use it as much as it should.  An XML Literal is like a String (http://msdn.microsoft.com/en-us/library/system.string.aspx) Literal, only instead of starting and ending with w…
Introduction When many people think of the WebBrowser (http://msdn.microsoft.com/en-us/library/2te2y1x6%28v=VS.85%29.aspx) control, they immediately think of a control which allows the viewing and navigation of web pages. While this is true, it's a…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…

715 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