Strict On

P

Peter Osawa

Hi, I'm trying to retreive outlook contact info with the phone number...

I code this with Option Strict On:

Dim myApp As New Outlook.Application
Dim contact As Outlook.ContactItem
Dim espace As Outlook.NameSpace
Dim contacts As Outlook.MAPIFolder

myApp = New Outlook.Application
espace = myApp.GetNamespace("MAPI")
contacts = espace.GetDefaultFolder(OlDefaultFolders.olFolderContacts)

contact = contacts.Items.Find("[BusinessTelephoneNumber]=0558XXXX") <<<---
Error

Me.Text = contact.FullName

And I have this error:

Option Strict On disallows implicit conversions from 'System.Object' to
'Outlook.ContactItem'.

I know Strict option is used for not melting types, but I don't know how
declare contact...

Any help ?

TIA
 
G

Guest

use CType for type casting. also, look up DirectCast and the difference between these two

tr
contact=CType(contacts.Items.Find("[BusinessTelephoneNumber]=0558XXXX"), outlook.contactitem
catc
'handle erro
finall
end tr

----- Peter Osawa wrote: ----

Hi, I'm trying to retreive outlook contact info with the phone number..

I code this with Option Strict On

Dim myApp As New Outlook.Applicatio
Dim contact As Outlook.ContactIte
Dim espace As Outlook.NameSpac
Dim contacts As Outlook.MAPIFolde

myApp = New Outlook.Applicatio
espace = myApp.GetNamespace("MAPI"
contacts = espace.GetDefaultFolder(OlDefaultFolders.olFolderContacts

contact = contacts.Items.Find("[BusinessTelephoneNumber]=0558XXXX") <<<--
Erro

Me.Text = contact.FullNam

And I have this error

Option Strict On disallows implicit conversions from 'System.Object' t
'Outlook.ContactItem'

I know Strict option is used for not melting types, but I don't know ho
declare contact..

Any help

TI
 
A

Armin Zingler

Peter Osawa said:
I code this with Option Strict On:

Dim myApp As New Outlook.Application
Dim contact As Outlook.ContactItem
Dim espace As Outlook.NameSpace
Dim contacts As Outlook.MAPIFolder

myApp = New Outlook.Application
espace = myApp.GetNamespace("MAPI")
contacts =
espace.GetDefaultFolder(OlDefaultFolders.olFolderContacts)

contact = contacts.Items.Find("[BusinessTelephoneNumber]=0558XXXX")
<<<--- Error

Me.Text = contact.FullName

And I have this error:

Option Strict On disallows implicit conversions from 'System.Object'
to 'Outlook.ContactItem'.

I don't know the object model, but I guess the return type of the Find
function is Object. This means the function could return any type of object,
so you'd get a runtime error if the object's type is not
Outlook.ContactItem. So, if you are sure that the function will always
return a Outlook.ContactItem object, you can write:

contact = directcast( _
contacts.Items.Find("[BusinessTelephoneNumber]=0558XXXX"),
Outlook.ContactItem _
)


--
Armin

How to quote and why:
http://www.plig.net/nnq/nquote.html
http://www.netmeister.org/news/learn2quote.html
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top