{"id":1105,"date":"2008-05-20T18:28:02","date_gmt":"2008-05-20T18:28:02","guid":{"rendered":"https:\/\/kweaver.org\/cs\/vbnet-windows\/"},"modified":"2008-05-20T18:28:02","modified_gmt":"2008-05-20T18:28:02","slug":"vbnet-windows","status":"publish","type":"post","link":"https:\/\/kweaver.org\/cs\/vbnet-windows\/","title":{"rendered":"VB.NET &#8211; Windows &#8211; Outlook"},"content":{"rendered":"<p style=\"margin-top: 0; margin-bottom: 0\">Here&#8217;s my code for marking a set of Tasks complete, based on the subject, and for creating a new Task:<\/p>\n<p style=\"margin-top: 0; margin-bottom: 0;\">&#160;<\/p>\n<p style=\"margin-top: 0; margin-bottom: 0;\">The part that bugs me the most, is the oNS.Login.&#160; I have to put in my exchange profile and my password and yet, Outlook still asks for my password.&#160; This is why I think that the application should be an outlook plug in. <\/p>\n<p style=\"margin-top: 0; margin-bottom: 0;\">&#160;<\/p>\n<p style=\"margin-top: 0; margin-bottom: 0;\"> &#8216; Create an Outlook application.<br \/>\nDim oApp As outlook.Application = New outlook.Application()<\/p>\n<p style=\"margin-top: 0; margin-bottom: 0;\">&#160;<\/p>\n<p style=\"margin-top: 0; margin-bottom: 0;\"> &#8216; Get NameSpace and Logon.<br \/>\nDim oNS As outlook.NameSpace = oApp.GetNamespace(&quot;mapi&quot;)<br \/>\n&#8216;    oNS.Logon(&quot;YourValidProfile&quot;, Missing.Value, False, True) &#8216; TODO:\n<\/p>\n<p style=\"margin-top: 0; margin-bottom: 0;\">&#160;<\/p>\n<p style=\"margin-top: 0; margin-bottom: 0;\"> &#8216; mark any uncompleted tasks to complete<br \/>\nDim oTasks As outlook.MAPIFolder = oNS.GetDefaultFolder(outlook.OlDefaultFolders.olFolderTasks)<\/p>\n<p style=\"margin-top: 0; margin-bottom: 0;\">&#160;<\/p>\n<p style=\"margin-top: 0; margin-bottom: 0;\"> &#8216; Get the first contact from the Contacts folder.<br \/>\nDim oItems As outlook.Items = oTasks.Items<br \/>\nDim oItem As outlook.TaskItem<\/p>\n<p style=\"margin-top: 0; margin-bottom: 0;\">&#160;<\/p>\n<p style=\"margin-top: 0; margin-bottom: 0;\"> oItems = oItems.Restrict(&quot;[Subject] = Change Infusion Set&quot;)<br \/>\nDim i As Integer<br \/>\nFor i = 1 To oItems.Count<br \/>\noItem = oItems.Item(i)<br \/>\nIf Not oItem.Complete Then oItem.MarkComplete()<br \/>\noItem.Save()<br \/>\nNext<\/p>\n<p style=\"margin-top: 0; margin-bottom: 0;\">&#160;<\/p>\n<p style=\"margin-top: 0; margin-bottom: 0;\"> &#8216; Create a new AppointmentItem.<br \/>\nDim oTask As outlook.TaskItem = oApp.CreateItem(outlook.OlItemType.olTaskItem)<\/p>\n<p>&#8216; Set some common properties.<br \/>\noTask.Subject = &quot;Change Infusion Set&quot;<br \/>\noTask.Body = &quot;Change Infusion Set&quot;<\/p>\n<p style=\"margin-top: 0; margin-bottom: 0;\">&#160;<\/p>\n<p style=\"margin-top: 0; margin-bottom: 0;\"> &#8216;Find number of days to add to task which is the smaller of the number of days or Total Insulin divided by TDD <br \/>\nDim days As Integer = Val(txtDays.Text)<br \/>\nDim StrDate As String<br \/>\nDim insulinDays As Integer = Val(txtTotal.Text) \/ Val(txtTDD.Text)<br \/>\nIf days &gt; insulinDays Then<br \/>\ndays = Int(insulinDays)<br \/>\nEnd If<br \/>\nStrDate = Convert.ToDateTime(Date.Today.AddDays(days))<\/p>\n<p style=\"margin-top: 0; margin-bottom: 0;\">&#160;<\/p>\n<p style=\"margin-top: 0; margin-bottom: 0;\">&#8216;Creating the Task <\/p>\n<p style=\"margin-top: 0; margin-bottom: 0;\"> oTask.StartDate = StrDate<br \/>\noTask.DueDate = StrDate<br \/>\noTask.Complete = False<br \/>\noTask.DateCompleted = Nothing<br \/>\noTask.Status = outlook.OlTaskStatus.olTaskNotStarted<\/p>\n<p style=\"margin-top: 0; margin-bottom: 0;\">&#160;<\/p>\n<p style=\"margin-top: 0; margin-bottom: 0;\"> If reminder = True Then<br \/>\noTask.ReminderSet = True<br \/>\nDim StrTime As String = Convert.ToString(Me.DateTimePicker1.Value.TimeOfDay)<br \/>\noTask.ReminderTime = Convert.ToDateTime(StrDate &amp; &quot; &quot; &amp; StrTime)<br \/>\nElse<br \/>\noTask.ReminderSet = False<br \/>\nEnd If<\/p>\n<p style=\"margin-top: 0; margin-bottom: 0;\">&#160;<\/p>\n<p style=\"margin-top: 0; margin-bottom: 0;\"> &#8216; Save to Tasks<br \/>\noTask.Save()<br \/>\n&#8216; Logoff.<br \/>\noNS.Logoff()<\/p>\n<p style=\"margin-top: 0; margin-bottom: 0;\">&#160;<\/p>\n<p style=\"margin-top: 0; margin-bottom: 0;\"> &#8216; Clean up.<br \/>\noApp = Nothing<br \/>\noNS = Nothing<br \/>\noTask = Nothing<\/p>\n<p style=\"margin-top: 0; margin-bottom: 0;\">&#160;<\/p>\n<p style=\"margin-top: 0; margin-bottom: 0;\">\n&#8216;Note I&#8217;ve lost my formatting, but I think you can get the point.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Here&#8217;s my code for marking a set of Tasks complete, based on the subject, and for creating a new Task: &#160; The part that bugs me the most, is the oNS.Login.&#160; I have to put in my exchange profile and my password and yet, Outlook still asks for my password.&#160; This is why I think [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-1105","post","type-post","status-publish","format-standard","hentry","category-blog"],"_links":{"self":[{"href":"https:\/\/kweaver.org\/cs\/wp-json\/wp\/v2\/posts\/1105","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/kweaver.org\/cs\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/kweaver.org\/cs\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/kweaver.org\/cs\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/kweaver.org\/cs\/wp-json\/wp\/v2\/comments?post=1105"}],"version-history":[{"count":0,"href":"https:\/\/kweaver.org\/cs\/wp-json\/wp\/v2\/posts\/1105\/revisions"}],"wp:attachment":[{"href":"https:\/\/kweaver.org\/cs\/wp-json\/wp\/v2\/media?parent=1105"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/kweaver.org\/cs\/wp-json\/wp\/v2\/categories?post=1105"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/kweaver.org\/cs\/wp-json\/wp\/v2\/tags?post=1105"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}