DLL returns a variant data type - how to convert and use in VB .NET

D

darrenbenn

I need to convert this code to VB .NET (2003).

Dim FaxMsg As IFaxMessage

Set FaxMsg = gFC.NewMessage

Dim Recip As Variant
' add a recipient to the fax recipients collection
Set Recip = FaxMsg.Recipients.Add(0)
Recip.Name = sWho
Recip.Company = sCompany
Recip.FaxNumber = sPhone

The problem I am having is that variant type does not exist in .NET and
FaxMsg.Recipients.Add(0) returns a variant type. I have Option Strict
and Option Explicit set to On. The upgrade utility converts the Variant
to type Object which is no good as I can't access Name, Company and
FaxNumber properties of Recip.

Thanks in advance

Darren Benn
MCSD
 
R

Rad [Visual C# MVP]

I need to convert this code to VB .NET (2003).

Dim FaxMsg As IFaxMessage

Set FaxMsg = gFC.NewMessage

Dim Recip As Variant
' add a recipient to the fax recipients collection
Set Recip = FaxMsg.Recipients.Add(0)
Recip.Name = sWho
Recip.Company = sCompany
Recip.FaxNumber = sPhone

The problem I am having is that variant type does not exist in .NET and
FaxMsg.Recipients.Add(0) returns a variant type. I have Option Strict
and Option Explicit set to On. The upgrade utility converts the Variant
to type Object which is no good as I can't access Name, Company and
FaxNumber properties of Recip.

Thanks in advance

Darren Benn
MCSD

You can cast the object into the correct type using the CType method. So if
the type you want is a Recipient you would do it like so

dim temp as object

temp = FaxMsg.Recipients.Add(0)

dim Recip as Recipient = CType(temp, Recipient)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top