none
Why is the value of the variables changed in another event? RRS feed

  • Question

  • Why is the value of the variables changed in another event?
     
    I made a little modification base on sample code  Outlook 2010: Developing an Inspector Wrapper.
     
    In the following code, I intend to get the properties from the Reply event, and then in the Send event to do further processing. But why does the value of oSender, ReceivedTime, MailSubject change in the Send event?
     
    The reulst is:
     
    Reply event:
    1,oSender:leon1526@yeah.net
    ReceivedTime:2017/3/1 23:14:58
    MailSubject:mail
    ---------------------------
    Send event:
    2,oSender:
    ReceivedTime:0:00:00
    MailSubject:
    Friend Class MailItemWrapper 
        Inherits InspectorWrapper
    
        Private m_item As Outlook.MailItem
    
        Private oSender As String
        Private oReceivedTime As Date
        Private oSubject As String
    
        Public Property Item As Outlook.MailItem
            Get
                Return m_item
            End Get
            Private Set(ByVal value As Outlook.MailItem)
                m_item = value
            End Set
        End Property
    
        Public Sub New(ByVal inspector As Outlook.Inspector) 
            MyBase.New(inspector)
        End Sub
    
        Protected Overloads Overrides Sub Initialize()
            Item = DirectCast(Inspector.CurrentItem, Outlook.MailItem)
            AddHandler Item.Open, AddressOf Item_Open
            AddHandler Item.Write, AddressOf Item_Write
            AddHandler Item.Reply, AddressOf Item_Reply
            AddHandler Item.ReplyAll, AddressOf Item_Reply
            AddHandler Item.Send, AddressOf Item_send
        End Sub
    
    
        Private Sub Item_Reply(ByVal Response As Object, ByRef Cancel As Boolean)
            Item = DirectCast(Inspector.CurrentItem, Outlook.MailItem)
            oSender = Item.SenderEmailAddress
            oReceivedTime = Item.ReceivedTime
            oSubject = Item.Subject
            MsgBox("1,oSender:" & oSender & vbCrLf & "oReceivedTime:" & oReceivedTime & vbCrLf & "oSubject:" & oSubject)
        End Sub
    
        Private Sub Item_send(ByRef Cancel As Boolean)
            Item = DirectCast(Inspector.CurrentItem, Outlook.MailItem)
            MsgBox("2,oSender:" & oSender & vbCrLf & "oReceivedTime:" & oReceivedTime & vbCrLf & "oSubject:" & oSubject)
        End Sub
    
    End Class
    
    


    • Edited by leon1526 Monday, March 6, 2017 1:23 PM update describe
    Monday, March 6, 2017 1:22 PM

Answers

  • Hello Leon,

    I have noticed the following lines of code:

     Private Sub Item_Reply(ByVal Response As Object, ByRef Cancel As Boolean)
            Item = DirectCast(Inspector.CurrentItem, Outlook.MailItem)
    

    You need to use the Response object instead of getting the currently displayed item in the inspector window.


    profile for Eugene Astafiev at Stack Overflow, Q&A for professional and enthusiast programmers

    Monday, March 6, 2017 1:51 PM

All replies

  • Hello Leon,

    I have noticed the following lines of code:

     Private Sub Item_Reply(ByVal Response As Object, ByRef Cancel As Boolean)
            Item = DirectCast(Inspector.CurrentItem, Outlook.MailItem)
    

    You need to use the Response object instead of getting the currently displayed item in the inspector window.


    profile for Eugene Astafiev at Stack Overflow, Q&A for professional and enthusiast programmers

    Monday, March 6, 2017 1:51 PM
  • Hi Eugene,

    I find a long time but I still can not find the use of Response object. Would you please let me know how to use it instead of CurrentItem? Thanks you very much.

    Wednesday, March 8, 2017 3:07 PM