Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

recursive loops and counting

Status
Not open for further replies.

sramey00

Programmer
Jun 9, 2004
149
0
0
US
i am using a recurisive loop that counts all items in the folders. when it completes, i would like it to give me a total count.

Code:
Sub ProcessFolder(ByRef StartFolder As Microsoft.Office.Interop.Outlook.MAPIFolder, ByRef RootFolder As Microsoft.Office.Interop.Outlook.MAPIFolder)
        Dim objFolder As Microsoft.Office.Interop.Outlook.MAPIFolder
        Dim objRootFolder As Microsoft.Office.Interop.Outlook.MAPIFolder
        Dim objItem As Object

        On Error Resume Next

        intCount = intCount + StartFolder.Items.Count
        objRootFolder = RootFolder

        For Each objFolder In StartFolder.Folders
            writeLog(objFolder.Name.ToString & ": " & objFolder.Items.Count)
            Call ProcessFolder(objFolder, objRootFolder)
        Next objFolder

        objFolder = Nothing



        If objRootFolder.Name = "" Then
            writeLog("Total Items in Mailbox: " & intCount)
        End If



    End Sub



    Sub writeLog(ByVal strText As String)

        Dim sPath As String = "C:\CountItemLog.txt"

        Dim LogFileStream As New IO.FileStream(sPath, IO.FileMode.Append, IO.FileAccess.Write)
        Dim LogStreamWriter As New IO.StreamWriter(LogFileStream)

        LogStreamWriter.WriteLine(strText)
        
        LogStreamWriter.Close()


    End Sub

i have the code segments to use this (above), however when i write to my output log file, the output is formatted how i want.

my log will look like this:

name of store: 0
Total items in store: 0
folder1: 67
Total items in store: 67
folder2: 21
Total items in store: 88

Total items in store: 88
Total items in store: 88

I know i need some type of if statement to allow writing of the total combined count to the log file, however i am out of ideas of how to create this...

i would like the log file to look like this:

name of store: 0
folder1: 67
folder2: 21
Total items in store: 88

any suggestions?


 
Hi.

Why are you using ByREF in the ProcessFolder sub?
 
Code:
sub ProcessFolder(ByRef StartFolder As Microsoft.Office.Interop.Outlook.MAPIFolder, ByRef RootFolder As Microsoft.Office.Interop.Outlook.MAPIFolder)
    writeLog("Total Items in Mailbox: " & ProcessFolderrec(StartFolder,RootFolder))
end sub

function ProcessFolderrec(ByRef StartFolder As Microsoft.Office.Interop.Outlook.MAPIFolder, ByRef RootFolder As Microsoft.Office.Interop.Outlook.MAPIFolder)
        Dim objFolder As Microsoft.Office.Interop.Outlook.MAPIFolder
        Dim objRootFolder As Microsoft.Office.Interop.Outlook.MAPIFolder
        Dim objItem As Object

        On Error Resume Next

        intCount = intCount + StartFolder.Items.Count
        objRootFolder = RootFolder

        For Each objFolder In StartFolder.Folders
            writeLog(objFolder.Name.ToString & ": " & objFolder.Items.Count)
            Call ProcessFolder(objFolder, objRootFolder)
        Next objFolder

        objFolder = Nothing
        return intcount
    End Sub

    Sub writeLog(ByVal strText As String)
        Dim sPath As String = "C:\CountItemLog.txt"

        Dim LogFileStream As New IO.FileStream(sPath, IO.FileMode.Append, IO.FileAccess.Write)
        Dim LogStreamWriter As New IO.StreamWriter(LogFileStream)

        LogStreamWriter.WriteLine(strText)
        
        LogStreamWriter.Close()
    End Sub

Christiaan Baes
Belgium

"My new site" - Me
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top