dwe0608
asked on
vb.net - Outlook - Counting the number of items in a conversation
Merry Christmas guys ...
I am implementing a function will will return the number of items in an Outlook Conversation - I have cobbled the following together and whilst no error is thrown - it doesnt seem to return the correct count:
Can someone assist to ensure that the correct count of the items in the conversation are returned?
MTIA
DWE
I am implementing a function will will return the number of items in an Outlook Conversation - I have cobbled the following together and whilst no error is thrown - it doesnt seem to return the correct count:
Function GetConv(mailItem As Outlook.MailItem)
Dim Conversation As Outlook.Conversation ' Get the conversation
Dim Items As Outlook.SimpleItems
Dim expMessage$
' // If Item = a MailItem.
Try
If TypeOf (mailItem) Is Outlook.MailItem Then
Conversation = mailItem.GetConversation
If Not IsNothing(Conversation) Then
Items = Conversation.GetChildren(mailItem)
GetConv = Items.Count
End If
Else
GetConv = 0
End If
Catch ex As SystemException
expMessage = ex.Message
MsgBox(expMessage)
GetConv = 0
End Try
End Function
Can someone assist to ensure that the correct count of the items in the conversation are returned?
MTIA
DWE
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks for the help ... Merry Christmas and Happy New Year to you and yours.
Honestly, I see a lot of discussion from time to time about disposing of objects or not. I still often do it, but have never found a single definitive answer to the question. There are arguments for and against and hard to sort out fact from fiction sometimes. In theory any variables that are scoped to a function or procedure are freed up after that procedure ends, but the runtime engine decided when the space from those objects gets released ("garbage collection"). Within a procedure, if I am going to reuse the same variable to reference multiple occurrences of an object type (one at a time, in a loop say) I often will set the variable to Nothing between uses, just to make sure I don't pick up the prior value somehow. Beyond that it seems to be somewhat a personal choice, from my perspective...
»bp
»bp
ASKER
Thanks for that Bill ... I agree with what you say ... I don't program enough nowadays to have an opinion on it, but there are some procedures I have written where it just doesn't seem natural to leave the objects seemingly alive when the function or sub exits ...
ASKER
I haven't done a lot of VB.Net stuff - in VB6 I would have disposed of the objects by setting them to nothing (ie set Conversation = nothing) ... is it still good practice to do that ... (ie maybe like this conversation = nothing) - I notice that the set assignment is no longer supported...
Open in new window