Board index » Visual Studio » trouble with loop structure in vb.net
|
n7cix
|
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? - |
