COMatePLUS and Outlook

Just starting out? Need help? Post your questions and find answers here.
schneider_ms
User
User
Posts: 15
Joined: Fri Mar 12, 2010 8:17 am
Location: Germany Saarland
Contact:

COMatePLUS and Outlook

Post by schneider_ms »

I want to read some appointments from outlook using the COMatePlus api.
In VB the following code works:

Code: Select all

Set myOlApp = CreateObject("Outlook.Application")
Set olNameSpace = myOlApp.GetNamespace("MAPI")
Set myAppointments = olNameSpace.GetDefaultFolder(olFolderCalendar).Items
Find$ = "[Start] >= '" & tdystart & "'"
Set currentAppointment = myAppointments.Find(Find$)
In PureBasic I tried:

Code: Select all

OutlookObject = COMate_CreateObject("Outlook.Application")
str_kommando$ = "GetNamespace(" + Chr(39) + "MAPI" + Chr(39) + ")"
ns = OutlookObject\GetObjectProperty(str_kommando$)
myfolder = ns\GetObjectProperty ("GetDefaultFolder(9)") ; olFolderCalendar
If Not myfolder 
       MessageRequester("Error", COMate_GetLastErrorDescription()) 
EndIf
items = myfolder\getObjectProperty("Items")
If Not items
        MessageRequester("Error Automation Outlook", COMate_GetLastErrorDescription()) 
EndIf
DateToCheck$ = "Find([Start] >= '08/26/2011' AS DATE)"
item = items\GetObjectProperty(DateToCheck$)
If Not item
        Debug COMate_GetLastErrorDescription()
EndIf
Debug item\getStringProperty("Subject")

The debug window show the following error:
"One or more arguments are invalid. Possibly a numerical overflow or too many nested objects, -if so, try splitting your method call into two or more subcalls."

What can I do?

best regards
Markus
User avatar
spikey
Enthusiast
Enthusiast
Posts: 750
Joined: Wed Sep 22, 2010 1:17 pm
Location: United Kingdom

Re: COMatePLUS and Outlook

Post by spikey »

The start property needs to be expressed as a string value not a date object. See http://msdn.microsoft.com/en-us/library/ff869662.aspx
Having said that I still can't get the Find method to work even using the correct syntax!
schneider_ms
User
User
Posts: 15
Joined: Fri Mar 12, 2010 8:17 am
Location: Germany Saarland
Contact:

Re: COMatePLUS and Outlook

Post by schneider_ms »

spikey wrote:The start property needs to be expressed as a string value not a date object. See http://msdn.microsoft.com/en-us/library/ff869662.aspx
Having said that I still can't get the Find method to work even using the correct syntax!
That is also my problem. No matter what I try it doesn't work.

I think the problem is that I have to pass a function call to comate.
In vb you can call
obj.find "[start] = ..."
Or
obj.restrict "[start] = ..."

How can I do this with comate?

Obj = Obj\getobjectproperty ("restrict " + find$ )

Does comate know that this should be a function call?
IdeasVacuum
Always Here
Always Here
Posts: 6426
Joined: Fri Oct 23, 2009 2:33 am
Location: Wales, UK
Contact:

Re: COMatePLUS and Outlook

Post by IdeasVacuum »

Take a look at this post, it might be an inspiration (or not):

http://www.purebasic.fr/english/viewtop ... 99&start=0

edit: Some related code by Spikey:

http://www.purebasic.fr/english/viewtop ... 13&t=46873
IdeasVacuum
If it sounds simple, you have not grasped the complexity.
schneider_ms
User
User
Posts: 15
Joined: Fri Mar 12, 2010 8:17 am
Location: Germany Saarland
Contact:

Re: COMatePLUS and Outlook

Post by schneider_ms »

There are some hints I followed but without success.
It is not a problem of invoke or setProperty or getProperty,
it is a problem of creating the command string:

Code: Select all

find$ = "Restrict(Start = '26/8/2011')" 
      
str_kommando = find$
hStatement = COMate_PrepareStatement(str_kommando)
If hStatement = 0
        MessageRequester("COMatePLUS!", "Couldn't create the statement!" + #CRLF$ + #CRLF$ + "COMatePLUS error : " + COMate_GetLastErrorDescription())
EndIf
Why doesnt this work?
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Re: COMatePLUS and Outlook

Post by srod »

No COMatePLUS will not like that statement in any kind of form!

I don't know anything about Outlook, but my guess would be that you might need to use an enumeration object to do what you are after.
I may look like a mule, but I'm not a complete ass.
schneider_ms
User
User
Posts: 15
Joined: Fri Mar 12, 2010 8:17 am
Location: Germany Saarland
Contact:

Re: COMatePLUS and Outlook

Post by schneider_ms »

srod wrote:No COMatePLUS will not like that statement in any kind of form!

I don't know anything about Outlook, but my guess would be that you might need to use an enumeration object to do what you are after.
I don't understand how enumeration would help me with my problem. I need to find all appointments from outlook for a specific day.
I can find all appointments but if I find an appointment witch is recurrent than I have to do a complicate calculation if it belongs to the specific day.
To solve this, outlook vb provides the functions restrict and find. But I don't know how to bring these functions in comateplus.
User avatar
spikey
Enthusiast
Enthusiast
Posts: 750
Joined: Wed Sep 22, 2010 1:17 pm
Location: United Kingdom

Re: COMatePLUS and Outlook

Post by spikey »

@srod

Yes I've been playing with an enumeration but I'm having the same trouble with that too, which is why I haven't posted anything more detailed yet.

I think the problem is that there is a two tier enumeration kicking around. According to the documentation the Find method applies to a collection object and returns a collection. However I can't seem to apply the CreateEnumeration method to a previously obtained enumeration, but you don't appear to be able to use the GetObjectProperty result object either...

This is what I've got to so far - but both approaches fail, and I haven't come up with any good alternatives so far either - because of the issue with recurring appointments that Markus identifies...

Code: Select all

IncludePath "C:\Documents and Settings\david\My Documents\Development Projects\PureBasic Projects\Common\"
IncludeFile "COMatePLUS.pbi"

EnableExplicit

Define Outlook.COMateObject, NameSpace.COMateObject, Calendar.COMateObject, Item.COMateObject
; Define AllItems.COMateEnumObject 
Define AllItems.COMateObject
Define FindItems.COMateEnumObject
Define Command.S

CallDebugger

Outlook = COMate_CreateObject("Outlook.Application")
If Not Outlook
  Debug "Outlook:"
  Debug COMate_GetLastErrorDescription()
EndIf

Command = "GetNamespace(" + Chr(39) + "MAPI" + Chr(39) + ")"
NameSpace = Outlook\GetObjectProperty(Command)
If Not NameSpace
  Debug "NameSpace:"
  Debug COMate_GetLastErrorDescription()
EndIf

Calendar = NameSpace\GetObjectProperty ("GetDefaultFolder(9)") ; olFolderCalendar
If Not Calendar 
  Debug "Calendar:"
  Debug COMate_GetLastErrorDescription()
EndIf

;AllItems = Calendar\CreateEnumeration("Items")
AllItems = Calendar\GetObjectProperty("Items")
If Not AllItems
  Debug "AllItems:"
  Debug COMate_GetLastErrorDescription()
EndIf

Command = "Find(" + Chr(34) + "[Start] >= '01/01/2011'" + Chr(34) + ")"
FindItems = AllItems\CreateEnumeration(Command)

If FindItems
    
  Repeat 
    
    Item = FindItems\GetNextObject()
  
    If Item
      Debug Item\GetStringProperty("Subject")    
    EndIf
    
  Until Not(Item)
  
Else
  Debug "FindItems:"
  Debug COMate_GetLastErrorDescription()
  
EndIf

; Tidy up.
If Item
  Item\Release()  
EndIf

If FindItems
  FindItems\Release()
EndIf

If AllItems
  AllItems\Release()
EndIf

If Calendar
  Calendar\Release()
EndIf

If NameSpace
  NameSpace\Release()
EndIf

If Outlook
  Outlook\Release()
EndIf

Last edited by spikey on Sat Aug 27, 2011 1:35 pm, edited 1 time in total.
User avatar
spikey
Enthusiast
Enthusiast
Posts: 750
Joined: Wed Sep 22, 2010 1:17 pm
Location: United Kingdom

Re: COMatePLUS and Outlook

Post by spikey »

@srod:
Another question occurs to me. In this repeat loop, should I call Item\Release() at the end of the iteration before the next call to FindItems\GetNextObject()? In a real world scenario the Items collection is likely to have a lot of member objects and an enormous memory leak could ensue if not handled properly...

Code: Select all

Repeat 
    
    Item = FindItems\GetNextObject()
  
    If Item
      Debug Item\GetStringProperty("Subject")    
    EndIf
    
  Until Not(Item)
schneider_ms
User
User
Posts: 15
Joined: Fri Mar 12, 2010 8:17 am
Location: Germany Saarland
Contact:

Re: COMatePLUS and Outlook

Post by schneider_ms »

the problem is still there.
1) reading appointments from outlook in Purebasic seams possible but there is no way to use the find or restrict methods from outlook.
2) reading all appointments in purebasic and calculating the recurrent appointments is very very complicate.

solutions
1) use .net instead of Purebasic?
2) is there another mechanism that gives me all appointments of the current day?
3) use a google account and the api of google?
4) use a vb makro to retrieve the information and some new way to copy this information to purebasic?

has someone an idea that is realy working?
schneider_ms
User
User
Posts: 15
Joined: Fri Mar 12, 2010 8:17 am
Location: Germany Saarland
Contact:

Re: COMatePLUS and Outlook

Post by schneider_ms »

I found a library ScriptControl.
With this lib it should be possible to write some VB Code and run it in PureBasic.
Unfortunately the library produces the error:
purelibrary "StringExtension" is missing.
Where can I find this library? Or is there a newer version of
ScriptControl that works with PB 4.5?

regards
Markus
IdeasVacuum
Always Here
Always Here
Posts: 6426
Joined: Fri Oct 23, 2009 2:33 am
Location: Wales, UK
Contact:

Re: COMatePLUS and Outlook

Post by IdeasVacuum »

Could be this, some what curiously:

http://www.purebasic.fr/english/viewtopic.php?t=36556

If not gonzal's lib, then perhaps:

http://www.purebasic.fr/english/viewtop ... &view=next
IdeasVacuum
If it sounds simple, you have not grasped the complexity.
schneider_ms
User
User
Posts: 15
Joined: Fri Mar 12, 2010 8:17 am
Location: Germany Saarland
Contact:

Re: COMatePLUS and Outlook

Post by schneider_ms »

I know the userlib that makes the problem. It is ScriptControl from Thomas Schulz. But if there is no new version of this userlib - how else can I use vb scripts in PB?
User avatar
Kiffi
Addict
Addict
Posts: 1485
Joined: Tue Mar 02, 2004 1:20 pm
Location: Amphibios 9

Re: COMatePLUS and Outlook

Post by Kiffi »

schneider_ms wrote:how else can I use vb scripts in PB?
that's quite simple. Here is an example-code:

Code: Select all

IncludePath #PB_Compiler_Home + "\srod\comateplus\" ; adjust to your comate-path!
XIncludeFile "comateplus.pbi"
IncludePath ""

Define ScriptControl.COMateObject
Define VBS.s

ScriptControl = COMate_CreateObject("ScriptControl")

ScriptControl\SetProperty("Language = 'VBScript'")

VBS = PeekS(?VBS)
VBS = ReplaceString(VBS, "'", "$0027")

ScriptControl\Invoke("AddCode('" + VBS + "')")

MessageRequester("", ScriptControl\GetStringProperty("Eval('IPAddress')"))

ScriptControl\Release()

DataSection
  VBS:
  IncludeBinary "test.vbs"
  Data.b 0
EndDataSection
and here is an example vbs (just save as 'test.vbs'):

Code: Select all

strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set IPConfigSet = objWMIService.ExecQuery("Select IPAddress from Win32_NetworkAdapterConfiguration")
For Each IPConfig in IPConfigSet
	If Not IsNull(IPConfig.IPAddress) Then
		For i=LBound(IPConfig.IPAddress) To UBound(IPConfig.IPAddress)
			IPAddress = IPAddress & IPConfig.IPAddress(i) & vbCrLf
		Next
	End If
Next
Greetings ... Kiffi
Hygge
schneider_ms
User
User
Posts: 15
Joined: Fri Mar 12, 2010 8:17 am
Location: Germany Saarland
Contact:

Re: COMatePLUS and Outlook

Post by schneider_ms »

That's great. This is the best solution and it works.
Thank you very much.
Post Reply