Author Topic: Send outlook task  (Read 3613 times)

0 Members and 1 Guest are viewing this topic.

Offline Marc Van Cauwenberghe

  • Newbie
  • *
  • Posts: 13
Send outlook task
« on: October 04, 2009, 10:45:26 AM »
Hello,

would anyone be so kind to help me 'send an outlook task' in PB9
I picked up this VB6/VBA example:
Code: [Select]
Private Sub Command1_Click()

'declare and instanciate Outlook
Dim objOutlook As New Outlook.Application
'declare a task item
Dim objTask As Outlook.TaskItem

'create new task item
Set objTask = objOutlook.Session.GetDefaultFolder(olFolderTasks).Items.Add

'add reciptient name
objTask.Recipients.Add "First Last"

'Add subject
objTask.Subject = "Test"

'Add body
objTask.Body = "Test"

'set due date of tomorrow
objTask.DueDate = Now() + 1

'i don't know why but this step is necessary
objTask.Assign

'send the task
objTask.Send

'save it
objTask.Close olSave
End Sub

I have jet to tame the com beast but hope someone will help me.

Marc


Offline José Roca

  • Administrator
  • Hero Member
  • *****
  • Posts: 3126
  • Gender: Male
    • José Roca Software
Re: Send outlook task
« Reply #1 on: October 04, 2009, 05:07:31 PM »
 
Something like this:

Code: [Select]
%olSave = 0

'declare and instanciate Outlook
'Dim objOutlook As New Outlook.Application
DIM objOutlook AS DISPATCH
objOutlook = ANYCOM "Outlook.Application"

'create new task item
'Dim objTask As Outlook.TaskItem
'Set objTask = objOutlook.Session.GetDefaultFolder(olFolderTasks).Items.Add
DIM objTask AS DISPATCH
DIM olFolderTasks AS VARIANT
olFolderTasks = "<some value>"
OBJECT CALL objOutlook.Session.GetDefaultFolder(olFolderTasks).Items.Add TO objTask

'add reciptient name
'objTask.Recipients.Add "First Last"
DIM vPrm AS VARIANT
vPrm = "First Last"
OBJECT CALL objTask.Recipients.Add(vPrm)

'Add subject
'objTask.Subject = "Test"
vPrm = "Test"
OBJECT SET objTask.Subject = vPrm

'Add body
'objTask.Body = "Test"
vPrm = "Test"
OBJECT SET objTask.Body = vPrm

'set due date of tomorrow
'objTask.DueDate = Now() + 1

' Since PB doesn't natively support VT_DATE variants, you will need to use one
' of my wrapper functions, e.g. PB_SystemTimeToVarDate, located in the VARUTILS.INC
' file of my WINAPI headers.

'i don't know why but this step is necessary
'objTask.Assign
OBJECT CALL objTask.Assign

'send the task
'objTask.Send
OBJECT CALL objTask.Send

'save it
'objTask.Close olSave
vPrm = %olSave AS LONG
OBJECT CALL objTask.Close(vPrm)

Offline Janne Sikstrom

  • Newbie
  • *
  • Posts: 2
Re: Send outlook task
« Reply #2 on: August 21, 2014, 08:21:03 PM »
I need to be able to create tasks in Outlook. I have tried to get help in the forum PowerBasic.com but it is not responding, maybe they can not?
Try different properties as:
Start Date, DateCompleted, status, etc.

To pinpoint the problem, I tried to post one for VBA / VB6 and it works without problems. So no attribute is wrong or missing.
It creates an entry but no real content. I get NO errors!
Is there anyone who can give me a clue?

Thanks in advance

Code: [Select]
'///////////////////////////////////////////////////////////////////////////
'// Code: Send outlook task from José Roca ( www.jose.it-berater.org )
'// October 04, 2009
'///////////////////////////////////////////////////////////////////////////
#COMPILE EXE
#DIM ALL

#INCLUDE "Win32Api.inc"
'#INCLUDE "AfxTime.inc"
'#INCLUDE "CAfxTime.inc"

%olSave = 0
%NULL = 0


FUNCTION PBMAIN () AS LONG
'declare and instanciate Outlook
'Dim objOutlook As New Outlook.Application
DIM objOutlook AS DISPATCH
LOCAL st AS SYSTEMTIME
local vDate as variant
LOCAL S AS STRING
LOCAL iRET AS LONG

objOutlook = ANYCOM "Outlook.Application"

'create new task item
'Dim objTask As Outlook.TaskItem
'Set objTask = objOutlook.Session.GetDefaultFolder(olFolderTasks).Items.Add
DIM objTask AS DISPATCH
DIM olFolderTasks AS VARIANT
olFolderTasks = "13"
OBJECT CALL objOutlook.Session.GetDefaultFolder(olFolderTasks).Items.Add TO objTask

'//////  add reciptient name
'objTask.Recipients.Add "First Last"
DIM vPrm AS VARIANT

vPrm = "First Last"
OBJECT CALL objTask.Recipients.Add(vPrm)

''//////  Add subject
'objTask.Subject = "Test"
vPrm = "SubjTest"
OBJECT SET objTask.Subject = vPrm

'//////  Add body
'objTask.Body = "Test"
vPrm = "Bodytest"
OBJECT SET objTask.Body = vPrm

'//////  Add DueDate
st.wyear = 2014 : st.wmonth = 8 : st.wday = 18

iRet        =  MakeVariantDate (ST, vDate)  ' can add params later if this works
IF ISFALSE iREt THEN   ' success!
S     =  VariantDate (vDate)
' MSGBOX USING$ ("VARIANTVT #  VARIANT_#() # formatted &" , VARIANTVT(vDate), VARIANT#(vDate), S) ,,  "Returned"
ELSE
' MSGBOX USING$("Error_,  VARIANTVT_#()= #", VARIANTVT (vDate))
END IF
' Since PB doesn't natively support VT_DATE variants, you will need to use one
' of my wrapper functions, e.g. PB_SystemTimeToVarDate, located in the VARUTILS.INC
' file of my WINAPI headers.
OBJECT SET objTask.DueDate =   s

'//////  Assign
'i don't know why but this step is necessary
'objTask.Assign
OBJECT CALL objTask.Assign

'//////  send the task
'objTask.Send
OBJECT CALL objTask.Send

'//////  save it
'objTask.Close olSave
vPrm = %olSave AS LONG
OBJECT CALL objTask.Close(vPrm)
END FUNCTION

'///////////////////////////////////////////////////////////////////////////
'// Code: SystemTimeTOVariantTime and Variant date :from Michael Mattias
'// Sep 14th 2009
'///////////////////////////////////////////////////////////////////////////
FUNCTION MakeVariantDate (st AS SYSTEMTIME, vDate AS VARIANT) AS LONG

  LOCAL dDate AS DOUBLE
  LOCAL pVAPI  AS VARIANTAPI PTR
  LOCAL iret  AS LONG
 
  ' convert system time to a double:
  iRet =  SystemTimeTOVariantTime (st, dDate)  ' Returns true on success and fills dDate when so
  IF ISTRUE iRet THEN   ' the call succeeded
       '
       ' But that IS NOT a VT_DATE! It's a VT_DOUBLE!
       '  fix the value and type of passed variant variable
         pVAPI            = VARPTR (vDate)
         @pvAPI.vt        = %VT_DATE
         @pvAPI.vd.dblval = dDate
         
   ELSE ' function failed, most likely an invalid date time was passed
         LET vDate =  ERROR %DISP_E_OVERFLOW    ' "out of present range" closest I can find
   END IF
   
   FUNCTION =  ISFALSE (iRet)  ' return zero on no error.
END FUNCTION


FUNCTION VariantDate (vDate AS VARIANT) AS STRING
    LOCAL ST AS SYSTEMTIME
    LOCAL szDF AS ASCIIZ * 48,  szDate AS ASCIIZ * 48
    LOCAL szTF AS ASCIIZ * 48,  szTime AS ASCIIZ * 48
    LOCAL vbTime AS DOUBLE

    vbTime = VARIANT#(vDate)
    VariantTimeToSystemTime vbTime, St
    ' always format the date
    szDf          =  "yyyy'-'MM'-'dd"
    GetDateFormat    BYVAL %NULL, BYVAL %NULL ,st, szDf, szDate, SIZEOF (szDate)

    ' only add the time string if present
    IF FRAC (vbTime) THEN
         szTF     = "HH':'mm':'ss"  ' HH= 24 hour, hh= 12 hour
         GetTimeFormat    BYVAL %NULL, BYVAL %NULL ,st, szTF, szTime, SIZEOF (szTime)
         FUNCTION = szDate & $SPC & szTime
     ELSE
        FUNCTION      = szDate
     END IF
END FUNCTION