Microsoft KB Archive/263456

= OL98: How to Programmatically Find a User's Next Available Free Time =

Article ID: 263456

Article Last Modified on 11/23/2006

-

APPLIES TO


 * Microsoft Outlook 98 Standard Edition

-



This article was previously published under Q263456





SUMMARY
This article describes how to use Visual Basic or Visual Basic Scripting Edition (VBScript) and the FreeBusy method in Outlook to determine the next free time for a particular recipient.



MORE INFORMATION
Microsoft provides programming examples for illustration only, without warranty either expressed or implied, including, but not limited to, the implied warranties of merchantability and/or fitness for a particular purpose. This article assumes that you are familiar with the programming language being demonstrated and the tools used to create and debug procedures. Microsoft support professionals can help explain the functionality of a particular procedure, but they will not modify these examples to provide added functionality or construct procedures to meet your specific needs. If you have limited programming experience, you may want to contact a Microsoft Certified Partner or the Microsoft fee-based consulting line at (800) 936-5200. For more information about Microsoft Certified Partners, please visit the following Microsoft Web site:

https://partner.microsoft.com/global/30000104

For more information about the support options that are available and about how to contact Microsoft, visit the following Microsoft Web site:

http://support.microsoft.com/default.aspx?scid=fh;EN-US;CNTACTMS

The function in this section accepts a string value that contains the alias of the recipient and returns the date and time of the next available free time period according to the recipient's Free/Busy information.

If the alias cannot be resolved, the function returns the invalid date, 1/1/4501. This date is commonly used by Outlook to represent an empty date field. If you programmatically store this date in an Outlook field, the word &quot;None&quot; appears in the field's control.

If the current time period for the recipient is marked as &quot;free,&quot; the function returns the time that marked the beginning of the period, which is most likely in the past. For instance, if the current time is 1:43 PM and the recipient is currently marked as &quot;free,&quot; this function returns the current date and a time of 1:30:00 PM.

In this sample code, time periods are measured in 30 minute increments. You can change this by modifying the value that is assigned to the intSlotLength variable.

Variable data types are commented for compatibility with VBScript. Function GetNextFreeTime(strAlias)    ' As Date Dim olApplication  ' As Outlook.Application Dim olSession      ' As Outlook.NameSpace Dim olRecipient    ' As Outlook.Recipient Dim intSlotLength  ' As Integer Dim strFreeBusy    ' As String Dim intCurrentSlot ' As Integer Dim intFreeSlot    ' As Integer Dim dblFreeSlot    ' As Double Dim dtmFreeSlot    ' As Date

'get a reference to the Outlook session Set olApplication = CreateObject(&quot;Outlook.Application&quot;) Set olSession = olApplication.Session 'get a reference to the recipient Set olRecipient = olSession.CreateRecipient(strAlias) olRecipient.Resolve

'if the alias did not resolve, return an invalid date. If Not olRecipient.Resolved Then GetNextFreeTime = #1/1/4501# Exit Function End If

'get the free busy string intSlotLength = 30 strFreeBusy = olRecipient.FreeBusy(Date, intSlotLength, True) 'calculate the position of *now* in the free busy string intCurrentSlot = Int(DateDiff(&quot;n&quot;, Date, Now) \ intSlotLength) + 1

'get the position of next *free* in the free busy string intFreeSlot = InStr(intCurrentSlot, strFreeBusy, &quot;0&quot;) 'get the number of minutes into the day for my free slot dblFreeSlot = (intFreeSlot - 1) * intSlotLength 'get an actual date/time dtmFreeSlot = DateAdd(&quot;n&quot;, dblFreeSlot, Date) GetNextFreeTime = dtmFreeSlot End Function To use the function, you need to supply the alias of the recipient. You can also supply a resolvable e-mail address or display name. The following line of sample code shows how to display the next free time period in a message box for the current user (where objOutlookNameSpace is a valid Outlook NameSpace object). MsgBox GetNextFreeTime(objOutlookNameSpace.CurrentUser.Address)

