Solved

VB6 Variant (Array) to VB.NET Array

Posted on 2004-09-29
5
1,352 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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Since .Net 2.0, Visual Basic has made it easy to create a splash screen and set it via the "Splash Screen" drop down in the Project Properties.  A splash screen set in this manner is automatically created, displayed and closed by the framework itsel…
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 seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

746 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now