Solved

Why is this stopping?

Posted on 2006-06-20
2
185 Views
Last Modified: 2011-09-20
I'm trying to write a tool to retrieve all my Outlook 2003 appointments for me.  At this point, I'm just in the start of a test tool.  I've got a form with a listbox on it named ListBox1 into which I want to add all these.  Once I have this working it's on to the next step.

I'm running the following and I'm being told I have > 1000 appointments (which I do).  However, when I run this I get through about a dozen and then it goes off into never land.  The thumbwheel on the ListBox shrinks to nothing and the program doesn't return.  It's appearently gotten into some sort of fatal loop (and yet I'm not getting any exception).

Any thoughts?  I'm just looking for some code that will list all the subjects of all my appointments.

        Dim oApp As Outlook.Application = New Outlook.Application()

        Dim oNS As Outlook.NameSpace = oApp.GetNamespace("mapi")
        oNS.Logon("YourValidProfile", Missing.Value, False, True)

        Dim oCalendar As Outlook.MAPIFolder = oNS.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderCalendar)

        Dim oAppointments As Outlook.Items = oCalendar.Items

        MsgBox("Total : " & oAppointments.Count)

        ListBox1.Items.Clear()

        Dim oAppt As Outlook.AppointmentItem = Nothing

        oAppt = oAppointments.GetFirst

        Try

            While oAppt IsNot Nothing

                If Len(oAppt.Subject) = 0 Then

                    ListBox1.Items.Add("Nothing")

                Else

                    MsgBox(oAppt.Subject)

                    ListBox1.Items.Add(oAppt.Subject)

                    oAppt = oAppointments.GetNext

                End If

            End While

        Catch ex As Exception

            MsgBox(ex.Message & " " & ex.StackTrace)

        End Try
0
Comment
Question by:klamerus
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 14

Accepted Solution

by:
ptakja earned 500 total points
ID: 16947764
Here's the bug:

           While oAppt IsNot Nothing

                If Len(oAppt.Subject) = 0 Then

                    ListBox1.Items.Add("Nothing")
                    >>>>>>>>> If you get here, you are in an infinite loop since you never update the oAppt object like you do in the Else block.

                Else

                    MsgBox(oAppt.Subject)

                    ListBox1.Items.Add(oAppt.Subject)

>>>>>>>>>> You need to move this line OUTSIDE the If structure and you should be OK.
                    oAppt = oAppointments.GetNext

                End If

            End While
0
 
LVL 1

Author Comment

by:klamerus
ID: 16955983
Well, I only had the one to add "nothing" in the event that I had an appointment with no subject, so that I'd have something show up.

Doh!  I see the point about the GetNext.  I'm stuck on a loop on an item with no subject.
0

Featured Post

Ready to get started with anonymous questions?

It's easy! Check out this step-by-step guide for asking an anonymous question on Experts Exchange.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article explains how to create and use a custom WaterMark textbox class.  The custom WaterMark textbox class allows you to set the WaterMark Background Color and WaterMark text at design time.   IMAGE OF WATERMARKS STEPS Create VB …
1.0 - Introduction Converting Visual Basic 6.0 (VB6) to Visual Basic 2008+ (VB.NET). If ever there was a subject full of murkiness and bad decisions, it is this one!   The first problem seems to be that people considering this task of converting…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…

623 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