Announcement

Collapse
No announcement yet.

PBCC 5 OUTLOOK COM issue

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • PBCC 5 OUTLOOK COM issue

    Everything compiles and runs up to the remarked out code.

    Bob Mechler
    Code:
    #COMPILER PBCC 5
    #COMPILE EXE "pbsenddrafts.exe"
    #DIM ALL
    #INCLUDE "oOutLook.inc"
    FUNCTION PBMAIN
      LOCAL oOutLookApp AS Int__Application
      LOCAL oNameSpace AS Int__NameSpace
      LOCAL oFolders AS Int__Folders
      LOCAL oDraftFolder AS MAPIFolder
      LOCAL oMailItem AS Int__MailItem
      LOCAL lDraftItem AS LONG
      LOCAL sBody AS STRING
      DisplayResult "About to open OUTLOOK!"
    
      oOutLookApp = NEWCOM $PROGID_Outlook_Application
    
      IF ISFALSE ISOBJECT(oOutLookApp) THEN
        DisplayResult "Unable to open or start OUTLOOK!"
        EXIT FUNCTION
      ELSE
        DisplayResult "Outlook started!"
      END IF
    
      oNameSpace = oOutLookApp.GetNameSpace(UCODE$("MAPI"))
      IF ISFALSE ISOBJECT(oNameSpace) THEN
        DisplayResult "Unable to obtain a NameSpace"
        EXIT FUNCTION
      ELSE
        DisplayResult "Obtained a namespace"
      END IF
    
    
      oFolders = oNameSpace.Folders
      IF ISFALSE ISOBJECT(oFolders) THEN
        DisplayResult "Unable to obtain Folders collection"
        EXIT FUNCTION
      ELSE
        DisplayResult "Obtained a Folders collection"
      END IF
    
      oDraftFolder = oNameSpace.GetDefaultFolder(%olFolderDrafts)
      IF ISFALSE ISOBJECT(oDraftFolder) THEN
        DisplayResult "Unable to obtain oDraftFolder"
        EXIT FUNCTION
      ELSE
        DisplayResult "Obtained oDraftFolder"
      END IF
      IF oDraftFolder.Items.Count > 0 THEN
          DisplayResult "Number of items in the Draft Folder is " + STR$(oDraftFolder.Items.Count)
          FOR lDraftItem = oDraftFolder.Items.Count TO 1 STEP -1
              oMailItem = oDraftFolder.Items.Item(lDraftItem)
              IF ISFALSE ISOBJECT(oMailItem) THEN
                DisplayResult "Unable to obtain oMailItem"
                EXIT FUNCTION
              ELSE
                DisplayResult "Obtained oMailItem"
              END IF
              'oMailItem.Send
              'IF ISFALSE ISOBJECT(oDraftFolder) THEN
              '  DisplayResult "Unable to send mailitem"
              '  EXIT FUNCTION
              'ELSE
              '  DisplayResult "Mail item sent"
              'END IF
          NEXT lDraftItem
      END IF
      PRINT "Starting Shutdown"
      oMailItem = NOTHING
      oDraftFolder = NOTHING
      oNameSpace = NOTHING
      oOutLookApp = NOTHING
      DisplayResult "Shutdown complete"
      EXIT FUNCTION
    END FUNCTION
    SUB DisplayResult(msg AS STRING)
      PRINT msg
      PRINT "Press a key...";
      WAITKEY$
      LOCATE ,1
    END SUB

  • #2
    Code:
    FOR lDraftItem = oDraftFolder.Items.Count TO 1 STEP -1
              oMailItem = oDraftFolder.Items.Item(lDraftItem)
    Thses 'collection' items are generally zero-indexed; if true in this case it means your reference (to the "count" element) is invalid.

    MCM
    Michael Mattias
    Tal Systems Inc. (retired)
    Racine WI USA
    [email protected]
    http://www.talsystems.com

    Comment

    Working...
    X