Answered Check for the existence of a property (VB Script)

  • יום שני 27 פברואר 2012 20:00
     
     

    The following script fragment works nicely - well, almost:

        Set oOutlook   = CreateObject("Outlook.Application")
        Set oNamespace = oOutlook.GetNamespace("MAPI")
        Set oInbox    = oNamespace.GetDefaultFolder(InboxFolder)

        For Each oMail In oInbox.items
            If oMail.SenderEMailAddress = . . .

    It successfully checks the sender of each mail but it runs into trouble when a mail item does not have the property "SenderEMailAddress" (e.g. an Outlook Task item). Hence my question: How can I determine if this property exists? I could, of course, trap the resulting error condition but I am looking for a more elegant solution.

כל התגובות

  • יום שני 27 פברואר 2012 22:09
    מנחה דיון
     
     

    If IsNull(...) ?

    Bill

  • יום שני 27 פברואר 2012 22:33
     
     
    Sorry, checking IsNull or using VarType will both raise an error.
  • יום שני 27 פברואר 2012 22:36
    מנחה דיון
     
     

    Hi,

    If that's the case, I think you're stuck trapping the error.

    Bill

  • יום שני 27 פברואר 2012 23:15
     
     תשובה

    Thanks for your help. After some searching I did find a method that does not involve error trapping.

        Set oOutlook   = CreateObject("Outlook.Application")
        Set oNamespace = oOutlook.GetNamespace("MAPI")
        Set oInbox    = oNamespace.GetDefaultFolder(InboxFolder)

        For Each oMail In oInbox.items
            if oMail.Class = 43 then WScript.Echo oMail.SenderEMailAddress
        Next

    I was unable to locate a dictionary of classes but it seems that mail items are class 43 whereas tasks are 49.

  • יום שלישי 28 פברואר 2012 00:34