473,396 Members | 1,748 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

InvalidCastException with Outlook 2003

Hi

In my VB.net application i got on different times (and not allways) an
System.InvalidCastException.

The line of code is:

objAppointmentItem = objItems.GetFirst

Does anyone know what to do???
Peter
Nov 20 '05 #1
4 1572
Hi,

Enclose it in a try catch block. I would also turn option strict on.
Make sure you use ctype or directcast to convert between types.

Ken
--------------

"Peter van der Veen" <pvdveenRe_move_This @ no-spam-ming.vanbrug.nl>
wrote in message news:tu********************************@4ax.com:
Hi

In my VB.net application i got on different times (and not allways) an
System.InvalidCastException.

The line of code is:

objAppointmentItem = objItems.GetFirst

Does anyone know what to do???
Peter


--
Outgoing mail is certified Virus Free.
Checked by AVG Anti-Virus (http://www.grisoft.com).
Version: 7.0.230 / Virus Database: 263.0.0 - Release Date: 6/2/2004
Nov 20 '05 #2
Peter,
In addition to the other comments.

Use the TypeOf operator to ensure that you have an object of the type you
are expecting...

Dim objAppointmentItem as AppointmentItem

Dim obj As Object = objItems.GetFirst()

If TypeOf obj Is AppointmentItem Then
objAppointmentItem = DirectCast(obj, AppointmentItem)
' do stuff with objAppointmentItem
End If

Hope this helps
Jay

"Peter van der Veen" <pvdveenRe_move_This @ no-spam-ming.vanbrug.nl> wrote
in message news:tu********************************@4ax.com...
Hi

In my VB.net application i got on different times (and not allways) an
System.InvalidCastException.

The line of code is:

objAppointmentItem = objItems.GetFirst

Does anyone know what to do???
Peter

Nov 20 '05 #3

Thx, it works now.

Outlook 2003 is different than 2000. With 2000 i don't have had this
error

On Tue, 8 Jun 2004 08:14:29 -0500, "Jay B. Harlow [MVP - Outlook]"
<Ja************@msn.com> wrote:
Peter,
In addition to the other comments.

Use the TypeOf operator to ensure that you have an object of the type you
are expecting...

Dim objAppointmentItem as AppointmentItem

Dim obj As Object = objItems.GetFirst()

If TypeOf obj Is AppointmentItem Then
objAppointmentItem = DirectCast(obj, AppointmentItem)
' do stuff with objAppointmentItem
End If

Hope this helps
Jay

"Peter van der Veen" <pvdveenRe_move_This @ no-spam-ming.vanbrug.nl> wrote
in message news:tu********************************@4ax.com...
Hi

In my VB.net application i got on different times (and not allways) an
System.InvalidCastException.

The line of code is:

objAppointmentItem = objItems.GetFirst

Does anyone know what to do???
Peter


Nov 20 '05 #4
Peter,
Remember that a folder may have multiple kind of Items in the folder. I
suspect in Outlook 2000 you only had Appointment Items in the folder, hence
you code works. Where as with Outlook 2003 you now have a second kind of
item in that folder, hence the exception.

Also using SetColumns causes the type of item to change...

Hope this helps
Jay

"Peter van der Veen" <pvdveenRe_move_This @ no-spam-ming.vanbrug.nl> wrote
in message news:0j********************************@4ax.com...

Thx, it works now.

Outlook 2003 is different than 2000. With 2000 i don't have had this
error

On Tue, 8 Jun 2004 08:14:29 -0500, "Jay B. Harlow [MVP - Outlook]"
<Ja************@msn.com> wrote:
Peter,
In addition to the other comments.

Use the TypeOf operator to ensure that you have an object of the type you
are expecting...

Dim objAppointmentItem as AppointmentItem

Dim obj As Object = objItems.GetFirst()

If TypeOf obj Is AppointmentItem Then
objAppointmentItem = DirectCast(obj, AppointmentItem)
' do stuff with objAppointmentItem
End If

Hope this helps
Jay

"Peter van der Veen" <pvdveenRe_move_This @ no-spam-ming.vanbrug.nl> wrotein message news:tu********************************@4ax.com...
Hi

In my VB.net application i got on different times (and not allways) an
System.InvalidCastException.

The line of code is:

objAppointmentItem = objItems.GetFirst

Does anyone know what to do???
Peter

Nov 20 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: bob scola | last post by:
I have a csharp, VS 2003 solution for a winform application The application uses an object called a "matter" and the class is defined in matter.cs. I can load matter objects into a combobox ...
4
by: Max | last post by:
Hi, I would like to have a button and a combo box with options to select various versions of Microsoft Outlook: 2002, 2003. The user selects the email client and clicks the button. The only...
1
by: Joey Lee | last post by:
Hi, I am trying to send mail thru outlook. I have found some code on the web and ws trying it out. I was successful in creating a mail in the draft folder of outlook, however hangs for a long...
4
by: DOTNET | last post by:
Hi, Anybody help me regarding this error: I am assigning the values to the session variables when the button is clicked and passing these session variables to the next page and when I am...
0
by: QA | last post by:
I am using a Business Scorecard Accelarator in a Sharepoint Portal 2003 using SQL Server 2005 I am getting the following error: Error,5/7/2005 10:50:14 AM,580,AUE1\Administrator,"Specified cast is...
5
by: TM | last post by:
I would like to write a little app in Visual Basic .net as an add-in to Outlook 2003 so that I can quickly get a list of contact names and email addresses, then when I click on a name or email...
9
by: George McCullen | last post by:
I have an Outlook 2003 using Exchange Server 2003 Public Contacts Folder containing 20,000 Contacts. I am writing a VB .Net 2003 program that loops through all the contacts in a "for each oCt in...
11
by: Maximus | last post by:
Hi all, Has anyone been able to reterive the gradient selection colors used in outlook 2003? Basically, I have a grid showing a list of records and my client wants the selected row to have the...
5
by: John A. Bailo | last post by:
I have a program that I'm converting from Outlook 2000 to Outlook 2003. It basically opens Outlook and iterates through a series of items in a public folder. I was able to run this as a...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.