exceptional exception
exceptional exception

Reputation: 527

Google Calendar API create all day event VB.net

I'm trying to create an all day event in google calendar from a winforms app in vb.net. I can create an event fine using a start and end time, but I can't figure out how to make an event all day. The below commented out code works for a 'time of day' event.

        'Dim CalendarEvent As New Data.Event
        'Dim StartDateTime As New Data.EventDateTime
        'Dim datestr As String
        'datestr = UIFORM.REQDATE.Value.ToString("dd/MM/yyyy") & " 07:00 am"
        'StartDateTime.DateTime = Date.ParseExact(datestr, "dd/MM/yyyy hh:mm tt", System.Globalization.DateTimeFormatInfo.InvariantInfo)
        'datestr = UIFORM.REQDATE.Value.ToString("dd/MM/yyyy") & " 03:00 pm"
        'Dim EndDateTime As New Data.EventDateTime
        'EndDateTime.DateTime = Date.ParseExact(datestr, "dd/MM/yyyy hh:mm tt", System.Globalization.DateTimeFormatInfo.InvariantInfo)
        'CalendarEvent.Start = StartDateTime
        'CalendarEvent.End = EndDateTime
        'CalendarEvent.Description = "Inserted from Order Entry"
        'CalendarEvent.Summary = NUMBER & " - " & NAME
        'Authenticate()
        'service.Events.Insert(CalendarEvent, "primary").Execute()

According to a few sources, I need only specify the date without the time to make an event all day. Here's what I've tried:

Dim CalendarEvent As New Data.Event
    Dim datestr As String
    datestr = UIFORM.REQDATE.Value.ToString("yyyy-MM-dd")
    CalendarEvent.Start.Date = datestr
    CalendarEvent.End.Date = datestr
    CalendarEvent.Description = "Inserted from Order Entry"
    CalendarEvent.Summary = "all day test"
    Authenticate()
    service.Events.Insert(CalendarEvent, "primary").Execute()

as soon as it hits CalendarEvent.Start.Date = datestr, I get an object reference error.

Upvotes: 0

Views: 1320

Answers (1)

Joel Coehoorn
Joel Coehoorn

Reputation: 415735

I think you need to do this:

Dim datestr As String = UIFORM.REQDATE.Value.ToString("yyyy-MM-dd")
Dim StartDateTime As New Data.EventDateTime With {.Date = datestr}
Dim EndDateTime As New Data.EventDateTime With {.Date = datestr}

Dim CalendarEvent As New Data.Event With {
    .Start = StartDateTime,
    .End = EndDateTime,
    .Description = "Inserted from Order Entry",
    .Summary = "all day test"
}
Authenticate()
service.Events.Insert(CalendarEvent, "primary").Execute()

Based on the API reference here:

https://developers.google.com/resources/api-libraries/documentation/calendar/v3/csharp/latest/classGoogle_1_1Apis_1_1Calendar_1_1v3_1_1Data_1_1EventDateTime.html

And with further help from this Stack Overflow Question:

Creating a Google Calendar event in VB

Upvotes: 1

Related Questions