I'm a newbie VB.net programmer and have written some code to pull
event titles, dates and time from my Calendar which I then use in a
home automation program.

Oddly, my code ran great when I first ran it a few days ago.... but
then started acting strangely; i.e. suddenly not pulling all the
events, creating bogus dates and times, and throwing the following
error: "Index was out of range. Must be non-negative and less than the
size of the collection. Parameter name: index".

Frustrated, I left it alone to start new this morning.  So I ran it
and.... everything worked great!  So I ran it about 7 - 10 times....
when... it started acting up again! I'm at a complete lose why this
would be happening.

Any help on this would be greatly appreciated.

Thanks!

(BTW - I've remmed out the hs class statements as they are for the
home automation software)

Here is my Code:

Try

            'USER PREFERENCE SECTION

            'Minutes before Calendar Event time that you want
announcement; i.e. -15 = 15 minutes before event time
            Dim intAdvNotice As Integer = -15
            'Days you want to pull from Google Calendar; i.e. just the
day script run = 1, 2 for today plus tomorrow, etc.
            Dim intDays As Integer = 2

            'GOOGLE CALENDAR SETTINGS
            'Enter the XML link from Private Calendar of your Google
Calendar Settings
            Dim strURLwithCookie As String = "http://www.google.com/
calendar/feeds/xxxxxxxxx%40gmail.com/
private-8479cb957f4782c17d1114f46a873ed1/full"
            Dim objCalService As Google.GData.Calendar.CalendarService
            'Enter the Name of your Google Calendar that you want to
pull events from
            objCalService = New
Google.GData.Calendar.CalendarService("Test Cal")
            Dim query As Google.GData.Calendar.EventQuery
            query = New
Google.GData.Calendar.EventQuery(strURLwithCookie)



            Dim objToday As Date = DateTime.Today
            Dim objEventTime As Date



            'set the limits of the query
            query.StartTime = objToday
            query.EndTime = DateAdd(DateInterval.Day, intDays,
objToday)



            'get the events
            Dim calFeed As Google.GData.Calendar.EventFeed
            calFeed = objCalService.Query(query)




            'show the title of the calendar

            Dim intEventCount As Integer = calFeed.Entries.Count







            'display the events
            Dim entry As Google.GData.Calendar.EventEntry = New
Google.GData.Calendar.EventEntry


            For Each entry In calFeed.Entries

                Dim objDate As Date = entry.Times(0).StartTime.Date
                Dim objTime As Date =
entry.Times(0).StartTime.TimeOfDay.ToString
                Dim objCombined As Date =
entry.Times(0).StartTime.ToString
                Dim strEventTitle As String = entry.Title.Text
                Dim intExpiredTime As Integer = 0

                objEventTime = DateAdd("n", intAdvNotice, objTime)


                If DateAdd("n", intAdvNotice, objCombined) <
DateTime.Now Then
                    intExpiredTime = 1
                    MsgBox("Expired Event is " + strEventTitle + " " +
objTime + " " + objDate)
                    'hs.writelog("EVT", "Time has passed for Event " &
strEventTitle & " at time " & objTime)

                Else
                End If


                'Create New Event
                If intExpiredTime <> 1 Then

                    MsgBox("Creating Event " + strEventTitle + " " +
objTime + " " + objDate)

                    'hs.newtimeevent(strEventTitle, objEventTime,
objDate, 1, 1, 1, 1, 1, 1, 1, "", 1, "EventSpeaker.txt", "Pending
Announcements")
                    'hs.writelog("EVT", "Creating Event " &
strEventTitle)

                Else
                End If



            Next
        Catch ex As Exception

            MsgBox(ex.Message)

            'hs.WriteLog("*** ERROR ***", "Error encountered on line "
& Erl.ToString() & " of Gcalc.vb (" & ex.Message & ")")

        End Try

    End Sub


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Google Calendar Data API" group.
To post to this group, send email to 
[email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/google-calendar-help-dataapi?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to