problems converting this VB sample code to c#

  • Thread starter =?ISO-8859-1?Q?Kurt_H=E4usler?=
  • Start date
?

=?ISO-8859-1?Q?Kurt_H=E4usler?=

Hi. I am trying to get Outlook.Items SetColumns method to work, and have
found a relevant knowledge base article Q184462.

I cant cast it to a Outlook.ContactItem (like I would do if I didnt use
the SetColumns) and if I leave it as Object, it contains no FullName and
gives a compile error.

Here is the relevant VB code:

Sub SetColumns_Example()
Dim ol As Outlook.Application
Dim MyFolder As MAPIFolder
Dim itms As Items
Dim itm As Object
Dim dtmStart As Date, dtmEnd As Date
Dim lngElapsed As Long
Set ol = New Outlook.Application
Set MyFolder = ol.Session.GetDefaultFolder(10)
Set itms = MyFolder.Items
itms.SetColumns "[FullName],[CompanyName]"
Debug.Print "WITH SETCOLUMNS"
Debug.Print Time
Debug.Print "------------------"
dtmStart = Time
For Each itm In itms
Debug.Print itm.FullName & ", " & itm.CompanyName
Next

Why doesnt VB give a compile error, class Object does not contain FullName?

Here is my c# code so far:
---
Outlook.Items contactItems = contactsFolder.Items;

contactItems.SetColumns("FullName");

Outlook.ContactItem contact = (Outlook.ContactItem) contactItems.Item
(counter);

string fn = contact.FullName;
----

Without the SetColumns, the cast works. Doing it like the VB snippet,
i.e. contact as an object, I get the compile time error, object does not
contain FullName.

Any hints on how to get this to work in c#?

Thanks a lot.
 
C

Cor

Hi Kurt,

Did you know you are asking the VB.net language group how get something
working in C#? that is written in probably VB6.

But here are some links


VB->C#
<http://www.remotesoft.com/>


C# -> VB .NET Converters:

<http://www.kamalpatel.net/ConvertCSharp2VB.aspx>
<http://csharpconverter.claritycon.com/Default.aspx>
<http://www.ragingsmurf.com/vbcsharpconverter.aspx>
<http://www.aspalliance.com/aldotnet/examples/translate.aspx>
http://www.gotdotnet.com/Community/...mpleGuid=c622348b-18a9-47d6-8687-979975d5957d


<http://www.remotesoft.com/>
-> "Octopus"

I hope this helps?

Cor



Cor
 
M

Morten Wennevik

no, object does not contain much of anything.
I'm not sure why Visual Basic can successfully read
foreach(Object itm in itms)
{
// do stuff
}
Must be some Visual Basic thing that translates Object to Item (or
whatever itms contains)

Ignore the line
Dim itm As Object
and use
foreach(Item itm in itms)
{
// do stuff
}
Substitute "Item" with whatever object type itms contains

OR

cast itms to the proper object before accessing FullName
 

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