Microsoft KB Archive/171425: Difference between revisions
m (Text replacement - ">" to ">") |
m (Text replacement - "&" to "&") |
||
(One intermediate revision by the same user not shown) | |||
Line 32: | Line 32: | ||
== MORE INFORMATION == | == MORE INFORMATION == | ||
This code requires a reference to the | This code requires a reference to the "Microsoft Active Messaging 1.1 Object Library" (Olemsg32.dll). | ||
Copy the following code to a module: | Copy the following code to a module: | ||
<pre> Public Declare Sub Sleep Lib | <pre> Public Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long) | ||
Public objSession as MAPI.Session | Public objSession as MAPI.Session | ||
</pre> | </pre> | ||
Line 42: | Line 42: | ||
<pre> Private Sub Form_Load() | <pre> Private Sub Form_Load() | ||
Set objSession = CreateObject( | Set objSession = CreateObject("MAPI.Session") | ||
'Try to logon. This line of code will log you onto the current | 'Try to logon. This line of code will log you onto the current | ||
Line 77: | Line 77: | ||
Set objMessages = objInbox.Messages 'Set the messages object | Set objMessages = objInbox.Messages 'Set the messages object | ||
Set objMsgFilter = objMessages.Filter 'Set the Message Filter object | Set objMsgFilter = objMessages.Filter 'Set the Message Filter object | ||
objMsgFilter.Unread = True 'Set the filter's | objMsgFilter.Unread = True 'Set the filter's "Unread" | ||
'property to true (look for | 'property to true (look for | ||
'unread messages only). | 'unread messages only). | ||
'Loop through all of the unread messages. Get each item in | 'Loop through all of the unread messages. Get each item in | ||
'turn and determine if it's | 'turn and determine if it's "TimeReceived" property is | ||
'greater than the | 'greater than the "TimeReceived" stored in your static | ||
'variable | 'variable "dteLastItemReceived". If it is, this is a | ||
'new message and increment the counter. | 'new message and increment the counter. | ||
For i = 1 To objMessages.Count | For i = 1 To objMessages.Count | ||
Line 92: | Line 92: | ||
End If | End If | ||
Next i | Next i | ||
MsgBox | MsgBox "There are " & iNewMessages & " new unread messages " & _ | ||
"since the last time I checked" | |||
'Reset dteLastTimeSent to the TimeSent of the last message | 'Reset dteLastTimeSent to the TimeSent of the last message | ||
Line 114: | Line 114: | ||
</span><br /> | </span><br /> | ||
<br /> | <br /> | ||
THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED | THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.</blockquote> | ||
<span>Last reviewed: July 18, 1997</span><br /> | <span>Last reviewed: July 18, 1997</span><br /> | ||
[[../cpyright|©1997 Microsoft Corporation. All rights reserved. Legal Notices]].<br /> | [[../cpyright|©1997 Microsoft Corporation. All rights reserved. Legal Notices]].<br /> | ||
|} | |} |
Latest revision as of 12:30, 21 July 2020
Microsoft Knowledge Base
HOWTO: Writing an Active Messaging Inbox Agent in Visual Basic
Last reviewed: July 18, 1997
Article ID: Q171425
The information in this article applies to:
- Active Messaging Library, version 1.1
- Microsoft Visual Basic Learning, Professional, and Enterprise Editions for Windows, version 5.0
- Microsoft Visual Basic Standard, Professional, and Enterprise Editions, 32-bit only, for Windows, version 4.0
SUMMARY
This code sample demonstrates how to use Active Messaging to find out how many new, unread messages have been delivered to your Inbox since the last time this code was run.
While this task may be trivial, this code sample demonstrates the following Active Messaging tasks in Visual Basic:
- Setting a variety of objects.
- Using a message filter.
- Looping through a Messages collection.
This code assumes a client session exists and is logged onto the current user's Exchange account.
For more information about starting an Active Messaging session using the current user's default profile, please see the following article in the Microsoft Knowledge Base:
ARTICLE-ID: Q171422 TITLE : HOWTO: Logging on to Active Messaging Session with Default Profile
MORE INFORMATION
This code requires a reference to the "Microsoft Active Messaging 1.1 Object Library" (Olemsg32.dll).
Copy the following code to a module:
Public Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long) Public objSession as MAPI.Session
Copy the following code to the general declaration section of a form:
Private Sub Form_Load() Set objSession = CreateObject("MAPI.Session") 'Try to logon. This line of code will log you onto the current 'session. If this fails, the most likely reason is that you do not 'have an open session. 'The error -2147221231 MAPI_E_LOGON_FAILED will return. objSession.Logon ShowDialog:=False, NewSession:=False FindNewMessages End Sub Sub FindNewMessages() Dim objInbox As Folder 'Inbox Dim objMessages As Messages 'Messages collection Dim objOneMessage As Message 'One message from the message 'collection Dim objMsgFilter As MessageFilter 'Message Filter set to 'Unread=True Static dteLastItemReceived As Date 'Used to store the TimeReceived 'property of the last message in 'the inbox Dim i As Integer 'Loop counter Dim iNewMessages As Integer 'Counter for how many new 'messages there are iNewMessages = 0 Set objInbox = objSession.Inbox 'Set the inbox object Set objMessages = objInbox.Messages 'Set the messages object Set objMsgFilter = objMessages.Filter 'Set the Message Filter object objMsgFilter.Unread = True 'Set the filter's "Unread" 'property to true (look for 'unread messages only). 'Loop through all of the unread messages. Get each item in 'turn and determine if it's "TimeReceived" property is 'greater than the "TimeReceived" stored in your static 'variable "dteLastItemReceived". If it is, this is a 'new message and increment the counter. For i = 1 To objMessages.Count Set objOneMessage = objMessages.Item(i) If objOneMessage.TimeReceived > dteLastItemReceived Then iNewMessages = iNewMessages + 1 End If Next i MsgBox "There are " & iNewMessages & " new unread messages " & _ "since the last time I checked" 'Reset dteLastTimeSent to the TimeSent of the last message dteLastItemReceived = objOneMessage.TimeReceived End Sub
Keywords : ActMsg Last reviewed: July 18, 1997 |