Blog

  • VB.NET – Windows – Outlook

    Here’s my code for marking a set of Tasks complete, based on the subject, and for creating a new Task:

     

    The part that bugs me the most, is the oNS.Login.  I have to put in my exchange profile and my password and yet, Outlook still asks for my password.  This is why I think that the application should be an outlook plug in.

     

    ‘ Create an Outlook application.
    Dim oApp As outlook.Application = New outlook.Application()

     

    ‘ Get NameSpace and Logon.
    Dim oNS As outlook.NameSpace = oApp.GetNamespace("mapi")
    ‘ oNS.Logon("YourValidProfile", Missing.Value, False, True) ‘ TODO:

     

    ‘ mark any uncompleted tasks to complete
    Dim oTasks As outlook.MAPIFolder = oNS.GetDefaultFolder(outlook.OlDefaultFolders.olFolderTasks)

     

    ‘ Get the first contact from the Contacts folder.
    Dim oItems As outlook.Items = oTasks.Items
    Dim oItem As outlook.TaskItem

     

    oItems = oItems.Restrict("[Subject] = Change Infusion Set")
    Dim i As Integer
    For i = 1 To oItems.Count
    oItem = oItems.Item(i)
    If Not oItem.Complete Then oItem.MarkComplete()
    oItem.Save()
    Next

     

    ‘ Create a new AppointmentItem.
    Dim oTask As outlook.TaskItem = oApp.CreateItem(outlook.OlItemType.olTaskItem)

    ‘ Set some common properties.
    oTask.Subject = "Change Infusion Set"
    oTask.Body = "Change Infusion Set"

     

    ‘Find number of days to add to task which is the smaller of the number of days or Total Insulin divided by TDD
    Dim days As Integer = Val(txtDays.Text)
    Dim StrDate As String
    Dim insulinDays As Integer = Val(txtTotal.Text) / Val(txtTDD.Text)
    If days > insulinDays Then
    days = Int(insulinDays)
    End If
    StrDate = Convert.ToDateTime(Date.Today.AddDays(days))

     

    ‘Creating the Task

    oTask.StartDate = StrDate
    oTask.DueDate = StrDate
    oTask.Complete = False
    oTask.DateCompleted = Nothing
    oTask.Status = outlook.OlTaskStatus.olTaskNotStarted

     

    If reminder = True Then
    oTask.ReminderSet = True
    Dim StrTime As String = Convert.ToString(Me.DateTimePicker1.Value.TimeOfDay)
    oTask.ReminderTime = Convert.ToDateTime(StrDate & " " & StrTime)
    Else
    oTask.ReminderSet = False
    End If

     

    ‘ Save to Tasks
    oTask.Save()
    ‘ Logoff.
    oNS.Logoff()

     

    ‘ Clean up.
    oApp = Nothing
    oNS = Nothing
    oTask = Nothing

     

    ‘Note I’ve lost my formatting, but I think you can get the point.

  • VB.Net (2005) and using the Registry

    One of the decision I made on my program was to use the registry to store my data.  Everyone else does and we are talking 4 small values.  Using the registry with Visual Basic is not hard, just calls.

     

    Here’s how I retrieve the registry settings:

     

    Me.txtTDD.Text = GetSetting("InfusionSetHelper", "Settings", "TDD", "")
    Me.txtDays.Text = GetSetting("InfusionSetHelper", "Settings", "Days", "")
    Me.txtTotal.Text = GetSetting("InfusionSetHelper", "Settings", "Total", "")

     

    And here’s an example of setting them:

     

    SaveSetting("InfusionSetHelper", "Settings", "Days", strDays)

     

    Deleting a setting:

     

    DeleteSetting("InfusionSetHelper", "Settings", "TDD")

     

    While this works and does a nice job, the documentation at http://msdn.microsoft.com/en-us/library/cy6azwf7(VS.80).aspx says to do it another way, and that way is more compatible with Windows Mobile.  I may change this code.

  • Windows Mobile Program done

    I’ve got most of the logic complete on the Windows Mobile project and boy howdy, so far, I’ve learned a lot.  One of my goals today is to record all the things I’ve learned.

     

    However, I’ve decided to make some changes.  I really think that the Infusion Set Helper ought to be an Outlook PlugIn, since you have to log into Outlook if you have an exchange server, or at least I have to.

     

    I still want the Windows Mobile program to be a ToDay plugin, so there is still work to be done on that and learning curve.  But it IS coming along.

  • Status

    I have a Window Application (runs on the desktop).  It does the following:

    • Allows the user to input number of days to change set
    • Allows the user to input optional information about insulin usage
      • Total Units
      • Average Unit
    • Allows the user to chose if they want to be reminded at a particular time (do not have to have a reminder)
    • Marks all existing tasks with the same time as Completed
    • Creates a new task

     

    I need to make sure the reminder part works.

     

    Next step — create the SmartPhone Today plugin

     

    I have lots of ideas for the future.  This could be set up for any type of irregularly reoccuring tasks.

  • My best design thinking is in the shower

    I came up with this idea in the shower, and just realized while in the shower this morning that saving the Entry ID is silly — would work find if this was desktop only or mobile phone only application, but since both can write Tasks in the end, I need to do a search on the subject line.

  • Using ID with Microsoft Objects

    Just a quick note to remind me where this article is.  I’ve been looking at http://support.microsoft.com/kb/293152/ which I think will help me mark my tasks complete.

  • Update on my project

    Didn’t get to spend much time on the project, today.  I got appointments to create on my older Gateway tablet, but couldn’t get them to work on my new Lenovo, which is where I have working on this.  The weird part is that I couldn’t Add an Reference to the Microsoft Office PIAs, but when I transferred the program to the other computer using my network, added the code to create a task, and then moved it back, the PIA reference was there. Weirdness.

     

    I’ve decided to add a "reminder time" to the project, and with a little research found I can use the DateTimePicker to get my time. 

     

    And now I’m fighting with the notebook again.  The district installed Groupwise which is getting into the way.  I am deleting the Groupwise account now, but am probably going to have to uninstall Groupwise.

  • Documentation can be SO irritating!

    I decided I wanted to do the regular Windows to Outlook side of the project first.  It makes sense having both, as I often change my sets in the morning, in front of my desktop computers.

     

    So I wanted to figure out how to create an Outlook item.  I started with this article:

     

    http://support.microsoft.com/kb/313787

     

    Lovely article but I couldn’t get it to compile.  I started doing research on the error message and kept running into references to PIA’s.  I found them, and I had to install them.

     

    http://www.microsoft.com/downloads/thankyou.aspx?familyId=59daebaa-bed4-4282-a28c-b864d8bfa513&displayLang=en

     

    I also found this article which was helpful too:

     

    http://msdn.microsoft.com/en-us/library/bb226711.aspx#officeoutlook2007whatsnewdeveloperspart1__intro

     

    So here is what I had to do to create an Outlook Calendar entry (which does work).

     

    I had to add an reference to the PIAs:

     

    Add a reference to the PIAs. To do this, follow these steps:

    a. On the Project menu, click Add Reference.
    b. Click the NET tab, locate Microsoft.Outlook.Interop.Outlook, and then click Select.
    c. In the Add References dialog box, click OK

     

    The next thing I had to do was to add the following statement to the top of the program:

     

    It now looks like:

     

    Imports System.Reflection
    Imports outlook = Microsoft.Office.Interop.Outlook

     

    Module Module1

     

    Sub Main()
    ‘ Create an Outlook application.
    Dim oApp As Outlook.Application = New Outlook.Application()

     

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

     

    ‘ Create a new AppointmentItem.
    Dim oAppt As Outlook.AppointmentItem = oApp.CreateItem(Outlook.OlItemType.olAppointmentItem)
    ‘oAppt.Display(true) ‘Modal

     

    ‘ Set some common properties.
    oAppt.Subject = "Created using OOM in C#"
    oAppt.Body = "Hello World"
    oAppt.Location = "Samm E"

     

    oAppt.Start = Convert.ToDateTime("11/30/2001 9:00:00 AM")
    oAppt.End = Convert.ToDateTime("11/30/2001 1:00:00 PM")

     

    oAppt.ReminderSet = True
    oAppt.ReminderMinutesBeforeStart = 5
    oAppt.BusyStatus = Outlook.OlBusyStatus.olBusy ‘ olBusy
    oAppt.IsOnlineMeeting = False

     

    ‘ Save to Calendar.
    oAppt.Save()

     

    ‘ Display.
    ‘oAppt.Display(true)

     

    ‘ Logoff.
    oNS.Logoff()

     

    ‘ Clean up.
    oApp = Nothing
    oNS = Nothing
    oAppt = Nothing
    End Sub

     

    End Module

     

     

     

     

  • First permutation of the project

    I’ve created a simple Windows — not Windows Mobile yet — application that shows the date of the next infusion change if the user has put in the number of days, or has put in the Total number of units and the average daily total. The application does several things I haven’t done before:

    1. Add days to the current date value — super easy — Date.Today.AddDays(intTDDDays) where the arguments is the number of days to add.
    2. Set values in the registry — again easy — SaveSetting("InfusionSetHelper", "Settings", "TDD", strTDD)
    3. Retrieve values in the registry — again easy — Me.txtTotal.Text = GetSetting("InfusionSetHelper", "Settings", "Total", "")

     

    So the next decision to be made, is do I make this a Windows program that updates outlook, so should I got straight to the Windows Mobile application.  I think having it both places might be useful.