COM Object Property not accessible

S

Saurabh

Hi Gurus,



We are in the process of writing a code in C# and have to use a dll written
in VB through interop and have come across an issue; In one of our other
development projects in Visual Basic 6.0, we are using the dll very
successfully to get a list of all properties of a class exposed by the dll;
say by using the code snippet OleObject.Contacts.Fields.



But when we tried the same thing in the .Net 2003 environment, we could not
get the list of fields. Although the Object browser show the Fields
collection but somehow I am not able to access it through code in the .NET
2003 environment. Here is the code snippet.



public OleObject.Contact oContact = new OleObject.ContactClass();



//Loop through the contact object to get a list of fields

for (int ictr = 0;ictr <= oContact.FieldCount;ictr++)

{

Console.WriteLine("Field : " + actContact.Fields(ictr));

}



Although we are able to access some other properties but not 'Fields'
property. Here is the error I am encountering Error: 'ocontact.Fields' does
not exist



Please help.



Thanks and Regards,

Saurabh
 
C

Christiaan van Bergen

Hi Saurabh,

In your code example you write

Console.WriteLine("Field : " + actContact.Fields(ictr));

But you get an error on 'ocontact.Fields' !! Was this a typo?

Christiaan
 
S

Saurabh

Hi Christiaan,

Yes, you are right. The line should have been

Console.WriteLine("Field : " + ocontact.Fields(ictr));

Sorry about that! Any solutions???

Saurabh
 
C

Christiaan van Bergen

Saurabh,

Isn't the oContact.Fields by any chance a property? You are using it as a
method.
If it is a property, and its type is some sort of array or list, use the
'[ ]' for accessing via index.

Console.WriteLine("Field : " + actContact.Fields[ictr]);

HTH
Christiaan
 

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