Board index » Visual Studio » trouble with loop structure in vb.net

trouble with loop structure in vb.net

Visual Studio317
I recentely migrated to vb.net and converted a small program from vb6. I

get a build error with the following error message.



"Expression is of type 'Outlook.Items', which is not a collection type."



The program uses a simple For Each ... Next loop to cycle through my Outlook

Contacts and searched for a specified record as shown below.



Private myContacts As Outlook.Items

Private Contact As Outlook.ContactItem

myOlApp = CreateObject("Outlook.application")

myNameSpace = myOlApp.GetNamespace("MAPI")

myContacts =

myNameSpace.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderContacts).Item

s

SearchLen = Len(txtSearchName.Text)

On Error GoTo SearchError

i = 1

'Cylcle through the records and store contacts matching search text

For Each Contact In myContacts

If UCase(VB.Left(Contacts.LastName, SearchLen)) =

UCase(txtSearchName.Text) Then

FirstNameStore(i) = Contacts.FirstName

.

.

.

i = i + 1

End If

Next Contact



The 'myContacts' variable is the one that triggers the error. It's not a

collection type as required by the For Each loop. The code worked fine in

vb6 but I'm at a total loss on how to correct the problem. Anyone who can

help?


-
 

Re:trouble with loop structure in vb.net

"Rooneyh" <rooneyh@msn.com>wrote in message

Quote
I recentely migrated to vb.net and converted a small program from

vb6.





--

<generic VB.Net response>

This newsgroup is for users of Visual Basic and whatever

VB.Net is, Visual Basic it isn't. While you may get a

stray answer to VB.NET questions here you should ask

them in newsgroups devoted exclusively to .NET

programming. Look for newsgroups with the word

"dotnet" in their name.



For the msnews.microsoft.com news server, try these:



microsoft.public.dotnet.general

microsoft.public.dotnet.languages.vb



</generic VB.Net response>





-