hi all,
i built outlook plug_in to change the numbers in contact list.when i tried the application for small contacts list ,it did the functionality i want.
but, when i used the application for large contacts . it did not change all the contacts item . Is the problem in the code /
Please help.


here is the code


Imports Extensibility
Imports System.Runtime.InteropServices
Imports System
Imports Microsoft.Office
Imports Microsoft.Office.Interop
Imports Microsoft.Office.Interop.Outlook
Imports Microsoft.Office.Core
Imports System.IO


#Region " Read me for Add-in installation and setup information. "
' When run, the Add-in wizard prepared the registry for the Add-in.
' At a later time, if the Add-in becomes unavailable for reasons such as:
' 1) You moved this project to a computer other than which is was originally created on.
' 2) You chose 'Yes' when presented with a message asking if you wish to remove the Add-in.
' 3) Registry corruption.
' you will need to re-register the Add-in by building the $SAFEOBJNAME$Setup project,
' right click the project in the Solution Explorer, then choose install.
#End Region

<GuidAttribute("F54D7C42-4A3B-4923-A10D-FF39357A8A82"), ProgIdAttribute("OutlookClient.Connect")> _
Public Class Connect
Implements Extensibility.IDTExtensibility2

Dim outLookApp As New Application()
Public WithEvents myOlApp As Outlook.Application
Dim applicationObject As Object
Dim addInInstance As Object
Dim pranth, pranth1 As String
Dim ext1 As String = ""
Dim num As String = ""
Dim con As Integer
Dim num1 As String = ""
Dim ext As String = ""
Dim ext2 As String = ""
Dim ext3 As String = " "
Dim exc As String = ""
Dim prantheses, prantheses1 As String
Dim WithEvents MyButton As CommandBarButton
Dim Pic As stdole.IPictureDisp, Mask As stdole.IPictureDisp

Public Sub OnBeginShutdown(ByRef custom As System.Array) Implements Extensibility.IDTExtensibility2.OnBeginShutdown
On Error Resume Next
' Notify the user you are shutting down, and delete the button.
MsgBox("Our custom Add-in is unloading.")
MyButton.Delete()
MyButton = Nothing
End Sub

Public Sub OnAddInsUpdate(ByRef custom As System.Array) Implements Extensibility.IDTExtensibility2.OnAddInsUpdate
End Sub

Public Sub OnStartupComplete(ByRef custom As System.Array) Implements Extensibility.IDTExtensibility2.OnStartupComplete
Dim oCommandBars As CommandBars
Dim oStandardBar As CommandBar
On Error Resume Next
'Dim ax As New MyAxHost

' Set up a custom button on the "Standard" command bar.
oCommandBars = applicationObject.CommandBars
If oCommandBars Is Nothing Then
' Outlook has the CommandBars collection on the Explorer object.
oCommandBars = applicationObject.ActiveExplorer.CommandBars
End If
oStandardBar = oCommandBars.Item("Standard")
If oStandardBar Is Nothing Then
' Access names its main toolbar Database.
oStandardBar = oCommandBars.Item("Database")
End If
' In case the button was not deleted, use the exiting one.
'MyButton = oStandardBar.Controls.Item("Update Contacts")
MyButton = oStandardBar.Controls.Item("Updating Phone Numbers")

' Pic = stdole.StdFunctions.LoadPicture("c:\images\picture.png")

If MyButton Is Nothing Then
MyButton = oStandardBar.Controls.Add(1)
With MyButton
.Caption = "Updating Phone Numbers"
.Style = MsoButtonStyle.msoButtonCaption
' .Picture.Picture = ""
.Tag = "Updating Phone Numbers"
.OnAction = "!<MyCOMAddin.Connect>"
.Visible = True

End With
End If
' Display a simple message to show which application you started in.
MsgBox("Phone number update utility has been added by Tawasul services Co.")
oStandardBar = Nothing
oCommandBars = Nothing
End Sub

Public Sub OnDisconnection(ByVal RemoveMode As Extensibility.ext_DisconnectMode, ByRef custom As System.Array) Implements Extensibility.IDTExtensibility2.OnDisconnection
On Error Resume Next
If RemoveMode <> Extensibility.ext_DisconnectMode.ext_dm_HostShutdown Then _
Call OnBeginShutdown(custom)
applicationObject = Nothing
End Sub

Public Sub OnConnection(ByVal application As Object, ByVal connectMode As Extensibility.ext_ConnectMode, ByVal addInInst As Object, ByRef custom As System.Array) Implements Extensibility.IDTExtensibility2.OnConnection
'MsgBox("On Connection In MyAddin")
applicationObject = application
addInInstance = addInInst
' If you aren't in startup, manually call OnStartupComplete.
If (connectMode <> Extensibility.ext_ConnectMode.ext_cm_Startup) Then _
Call OnStartupComplete(custom)

End Sub
Private Sub MyButton_Click(ByVal Ctrl As Microsoft.Office.Core.CommandBarButton, ByRef CancelDefault As Boolean) Handles MyButton.Click
addContact()
MsgBox("Your Contacts Phone numbers has been changed according to Kuwait Numbering Plan ")
End Sub

Public Sub addContact()
Dim total As Integer
Dim contacts As Outlook.MAPIFolder = outLookApp.ActiveExplorer().Session _
.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderContacts)
'exc = objFolder.Folders(1).Name.ToString()
' For Each foundContact2 As Outlook.ContactItem In objFolder.Folders(objFolder.Folders.Count).Items
'Next
'Dim objOutlook As Outlook._Application
'objOutlook = New Outlook.Application()
'Dim objNS As Outlook._NameSpace = objOutlook.Session
'Dim objFolder As Outlook.MAPIFolder = _
' objNS.Folders.Item("Personal Folders")

' objFolder = objFolder.Folders.Item("My Contacts")
'objFolder = objFolder.Folders.Item("Personal Folders")
' exc = objFolder.Folders.Count.ToString()
' exc = objFolder.Folders.GetFirst.Name.ToString() '& objFolder.Folders.GetNext.Name.ToString() & objFolder.Folders(2).Items.Count.ToString() & objFolder.Folders(2).Items.Item(788).ToString()

For Each foundContact As Outlook.ContactItem In contacts.Items

If Not (foundContact.BusinessTelephoneNumber Is Nothing) Then
foundContact.BusinessTelephoneNumber = expression(foundContact.BusinessTelephoneNumber.ToString)
foundContact.Save()
End If
If Not (foundContact.HomeTelephoneNumber Is Nothing) Then
foundContact.HomeTelephoneNumber = expression(foundContact.HomeTelephoneNumber.ToString)
foundContact.Save()
End If
If Not (foundContact.BusinessFaxNumber Is Nothing) Then
foundContact.BusinessFaxNumber = expression(foundContact.BusinessFaxNumber.ToString)
foundContact.Save()
End If

If Not (foundContact.MobileTelephoneNumber Is Nothing) Then
foundContact.MobileTelephoneNumber = expression(foundContact.MobileTelephoneNumber.ToString)
foundContact.Save()
End If
Next
For total = 1 To contacts.Folders.Count
For Each foundContact1 As Outlook.ContactItem In contacts.Folders(total).Items
If Not (foundContact1.MobileTelephoneNumber Is Nothing) Then
foundContact1.MobileTelephoneNumber = expression(foundContact1.MobileTelephoneNumber.ToString)
foundContact1.Save()
End If
If Not (foundContact1.BusinessTelephoneNumber Is Nothing) Then
foundContact1.BusinessTelephoneNumber = expression(foundContact1.BusinessTelephoneNumber.ToString)
foundContact1.Save()
End If
If Not (foundContact1.BusinessFaxNumber Is Nothing) Then
foundContact1.BusinessFaxNumber = expression(foundContact1.BusinessFaxNumber.ToString)
foundContact1.Save()
End If
If Not (foundContact1.HomeTelephoneNumber Is Nothing) Then
foundContact1.HomeTelephoneNumber = expression(foundContact1.HomeTelephoneNumber.ToString)
foundContact1.Save()
End If
Next
Next
End Sub
Public Function expression(ByVal tel1 As String) As String
If tel1.Contains("x Ext:") Then
ext1 = tel1.Substring(tel1.IndexOf("x Ext:"))
tel1 = tel1.Substring(0, tel1.IndexOf("x Ext:"))
End If
If tel1.Contains("Ext:") Then
ext1 = tel1.Substring(tel1.IndexOf("Ext:"))
tel1 = tel1.Substring(0, tel1.IndexOf("Ext:"))
End If
If tel1.Contains("EXT") Then
ext1 = tel1.Substring(tel1.IndexOf("EXT"))
tel1 = tel1.Substring(0, tel1.IndexOf("EXT"))
End If
If tel1.Contains("x ext") Then
ext1 = tel1.Substring(tel1.IndexOf("x ext"))
tel1 = tel1.Substring(0, tel1.IndexOf("x ext"))
End If
If tel1.Contains("ext") Then
ext1 = tel1.Substring(tel1.IndexOf("ext"))
tel1 = tel1.Substring(0, tel1.IndexOf("ext"))
End If
If tel1.Contains("x /") Then
ext1 = tel1.Substring(tel1.IndexOf("x /"))
tel1 = tel1.Substring(0, tel1.IndexOf("x /"))
ext1 = "x /" & getNum(ext1.Substring(3))
End If
If tel1.Contains("/") Then
ext1 = tel1.Substring(tel1.IndexOf("/"))
tel1 = tel1.Substring(0, tel1.IndexOf("/"))
ext1 = "/" & getNum(ext1.Substring(1))
End If
If tel1.Contains("-") Then
ext2 = tel1.Substring(0, tel1.IndexOf("-"))
tel1 = ext2 & tel1.Substring(tel1.IndexOf("-") + 1)

End If
If tel1.Contains("x") Then
ext1 = tel1.Substring(tel1.IndexOf("x"))
tel1 = tel1.Substring(0, tel1.IndexOf("x"))
End If
If tel1.Contains("00965") Then
ext = tel1.Substring(0, 5)
tel1 = getNum(tel1.Substring(5))
' tel1 = tel1.Substring(5)
ElseIf tel1.Contains("+965") Then
ext = tel1.Substring(0, 4)
' tel1 = tel1.Substring(4)
tel1 = getNum(tel1.Substring(4))
Else
tel1 = getNum(tel1)
End If
num1 = ext & tel1 & ext1
tel1 = ""
ext = ""
ext1 = ""
Return num1
End Function
Public Function getNum(ByVal tel As String) As String
If tel.Contains("/") Then
ext3 = tel.Substring(tel.IndexOf("/"))
tel = tel.Substring(0, tel.IndexOf("/"))
End If
con = Convert.ToInt32(tel)
If con = 777 Then
num = "112"
ElseIf con >= 800000 And con <= 899999 Then
num = "1" & con.ToString
ElseIf con >= 2000000 And con <= 4399999 Then
num = "2" & con.ToString
ElseIf con >= 4400000 And con <= 4499999 Then
num = "9" & con.ToString
ElseIf con >= 4500000 And con <= 5009999 Then
num = "2" & con.ToString
ElseIf con >= 5010000 And con <= 5029999 Then
num = "6" & con.ToString
ElseIf con >= 5030000 And con <= 5049999 Then
num = "2" & con.ToString
ElseIf con >= 5050000 And con <= 5199999 Then
num = "6" & con.ToString
ElseIf con >= 5200000 And con <= 5799999 Then
num = "2" & con.ToString
ElseIf con >= 5800000 And con <= 6999999 Then
num = "6" & con.ToString
ElseIf con >= 7000000 And con <= 7019999 Then
num = "6" & con.ToString
ElseIf con >= 7020000 And con <= 7029999 Then
num = "9" & con.ToString
ElseIf con >= 7030000 And con <= 7099999 Then
num = "6" & con.ToString
ElseIf con >= 7100000 And con <= 7699999 Then
num = "9" & con.ToString
ElseIf con >= 7700000 And con <= 7799999 Then
num = "6" & con.ToString
ElseIf con >= 7800000 And con <= 7999999 Then
num = "9" & con.ToString
ElseIf con >= 9000000 And con <= 9999999 Then
num = "9" & con.ToString
Else
num = con.ToString
End If
num = num & ext3
ext3 = ""
Return num
End Function


End Class

I have just started a new job and my first assignment is to figure out a bug in an application that appears to be based on the same code you have used. (The opening #Region is word for word as are many of the methods and other code.) I haven't been able to look over your code yet to see what your problem might be, but it might help us both if I knew where you got your outline.

Thanks,

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.