Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Progress bar Help

Posted on 2005-04-21
10
Medium Priority
?
220 Views
Last Modified: 2010-04-23
I have a program that I want to add a progress bar on.
The program searches through a directory strucure and if it finds a directory with anyfiles that have a  .dgn extension it outputs the data to my DataSource and then keeps on going.
What I want the Progress bar to do is to show how EACH directory is being prosessed.
Here is my main code that does all the Directory Searching

Thanks

    Public Sub ScanDir()
        Dim myPath As String = "\\Engineering\Projects\Working"
        Dim myDirectory As System.IO.Directory
        Dim mySubDirectory As String
        Dim myBridgeDirectory As String
        Dim myBridgePosition As Integer
        Dim myDesignFiles As String
        Dim FoundIt As Boolean
        Dim myDesignUnit As String
        Dim count As Integer


        ds = New dsBridgeDGNFiles
        Dim row As dsBridgeDGNFiles.tblFilesRow

        If optBridge.Checked = True Then
            myDesignUnit = "Bridge"
        ElseIf optBrgMaint.Checked = True Then
            myDesignUnit = "Bridge Maintenance"
        ElseIf optSignLight.Checked = True Then
            myDesignUnit = "SL Structures"
        ElseIf optLandScape.Checked = True Then
            myDesignUnit = "Landscape"
        End If



        Dim fileCount As Integer = 0
        Dim oDir As New System.IO.DirectoryInfo(myPath & "\" & myBridgeDirectory)
        'RecursiveCount(oDir, fileCount)


        If myDirectory.Exists(myPath) Then
            'Debug.WriteLine("Sub Directory List:")
            For Each mySubDirectory In myDirectory.GetDirectories(myPath)
                For Each myBridgeDirectory In myDirectory.GetDirectories(mySubDirectory)
                    'This routine checks to see if their are any files with a .dgn extension if so then process
                    If InStr(1, myBridgeDirectory, myDesignUnit) > 0 Then
                        myDesignFiles = Dir(myBridgeDirectory & "\*.dgn", vbDirectory)   ' Retrieve the first entry.
                        myDesignFiles = Dir()
                        'FoundIt = False

                        'If InStr(myDesignFiles, ".dgn") > 0 Then
                        '    Debug.WriteLine(myBridgeDirectory)
                        'End If

                        Do While myDesignFiles <> ""    ' Start the loop.
                            If InStr(myDesignFiles, ".dgn") > 0 Then
                                'Debug.WriteLine(myDesignFiles)
                                row = ds.tblFiles.NewtblFilesRow
                                row.DGNFiles = myDesignFiles
                                row.Directory = myBridgeDirectory
                                ds.tblFiles.Rows.Add(row)
                                'FoundIt = True
                                'Exit Do
                            End If
                            myDesignFiles = Dir()
                        Loop
                        'If FoundIt = True Then
                        'cboFiles.Items.Add(myBridgeDirectory)
                        'End If
                    End If

                Next
            Next
        Else
            MsgBox("The Projects Directory was not found Contact Stephen Herrick")
            Exit Sub
        End If

    End Sub
0
Comment
Question by:sherrick123
  • 4
  • 4
  • 2
10 Comments
 
LVL 12

Expert Comment

by:S-Twilley
ID: 13837679
Are you intentionally only going down two levels in the directory structure, or would you prefer to go down all levels?

When you say about the process through each directory?  do you mean to say that if there were 246 directories, show the progress as it goes through each of those directories.... or for say directory X.. it has 10 dgn files, the progress through each of those files ?
0
 

Author Comment

by:sherrick123
ID: 13837753
Only going two down.  That is where the files are going to be
yes I want it to show on each dgn file then start over when it gets to the next directory

ALTHOUGH it would be nice to have two progress bars.
One for the directories and one for the files.

hummmm

0
 
LVL 12

Expert Comment

by:S-Twilley
ID: 13838432
okies... one option is to store the last count of directories... and update it after each scan... this can lead to slight differences.

other way is to do a quick count of directories... then use that in the file scan.


HEre's code for the 2nd implementation:

progFile and progDirectory are progress bars
this code doesn't have the code to do the dataset stuff... just the file processing

Imports System.IO

==================================

    Public Sub ScanDir()
        Dim myPath As String
        Dim topDir, subDir, bottomDir As DirectoryInfo
        Dim thisFile, theseFiles() As FileInfo
        Dim dirCount As Integer = 0

        topDir = New DirectoryInfo("\\Engineering\Projects\Working\")

        For Each subDir In topDir.GetDirectories()
            For Each bottomDir In subDir.GetDirectories
                dirCount += subDir.GetDirectories.Length
            Next
        Next

        progDirectory.Value = 0
        progDirectory.Max = dirCount

        For Each subDir In topDir.GetDirectories()
            For Each bottomDir In subDir.GetDirectories
                If progDirectory.Value < progDirectory.Max Then progDirectory.Value += 1

                theseFiles = bottomDir.GetFiles("*.dgn")

                progFile.Value = 0
                progFile.Max = theseFiles.Length

                For Each thisFile In theseFiles
                    If progFile.Value < progFile.Max Then progFile.Value += 1

                    ' YOUR DATASET CODE
                Next

            Next
        Next

    End Sub
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:sherrick123
ID: 13838547
I'm sorry but I can't figure out how to impliment that in my code.

When do I do the count of sub directories and when do I put in the file count??

        Dim myPath As String = "\\Engineering\Projects\Working"
        Dim myDirectory As System.IO.Directory
        Dim mySubDirectory As String
        Dim myBridgeDirectory As String
        Dim myBridgePosition As Integer
        Dim myDesignFiles As String
        Dim FoundIt As Boolean
        Dim myDesignUnit As String
        Dim count As Integer


        ds = New dsBridgeDGNFiles
        Dim row As dsBridgeDGNFiles.tblFilesRow

        If optBridge.Checked = True Then
            myDesignUnit = "Bridge"
        ElseIf optBrgMaint.Checked = True Then
            myDesignUnit = "Bridge Maintenance"
        ElseIf optSignLight.Checked = True Then
            myDesignUnit = "SL Structures"
        ElseIf optLandScape.Checked = True Then
            myDesignUnit = "Landscape"
        End If



        Dim fileCount As Integer = 0
        Dim oDir As New System.IO.DirectoryInfo(myPath & "\" & myBridgeDirectory)
        'RecursiveCount(oDir, fileCount)


        If myDirectory.Exists(myPath) Then
            'Debug.WriteLine("Sub Directory List:")
            For Each mySubDirectory In myDirectory.GetDirectories(myPath)
                For Each myBridgeDirectory In myDirectory.GetDirectories(mySubDirectory)
   'This routine checks to see if their are any files with a .dgn extension in a particular directory if so then process
                    If Microsoft.VisualBasic.Right(myBridgeDirectory, Len(myDesignUnit)) = myDesignUnit Then
                        myDesignFiles = Dir(myBridgeDirectory & "\*.dgn", vbDirectory)   ' Retrieve the first entry.
                        myDesignFiles = Dir()
                        Do While myDesignFiles <> ""    ' Start the loop.
                            If InStr(myDesignFiles, ".dgn") > 0 Then
                                'Debug.WriteLine(myDesignFiles)
                                row = ds.tblFiles.NewtblFilesRow
                                row.DGNFiles = myDesignFiles
                                row.Directory = myBridgeDirectory
                                ds.tblFiles.Rows.Add(row)
                            End If
                            myDesignFiles = Dir()
                        Loop
                    End If
                Next
            Next
        Else
            MsgBox("The Projects Directory was not found Contact Stephen Herrick")
            Exit Sub
        End If

    End Sub
0
 
LVL 12

Expert Comment

by:S-Twilley
ID: 13838746
Ok.. i'll have a go.

======================

    Public Sub ScanDir()
        Dim myPath As String
        Dim topDir, subDir, bottomDir As DirectoryInfo
        Dim thisFile, theseFiles() As FileInfo
        Dim dirCount As Integer = 0

        Dim myDesignUnit As String

        topDir = New DirectoryInfo("\\Engineering\Projects\Working\")

        ds = New dsBridgeDGNFiles
        Dim row As dsBridgeDGNFiles.tblFilesRow

        If optBridge.Checked = True Then
            myDesignUnit = "Bridge"
        ElseIf optBrgMaint.Checked = True Then
            myDesignUnit = "Bridge Maintenance"
        ElseIf optSignLight.Checked = True Then
            myDesignUnit = "SL Structures"
        ElseIf optLandScape.Checked = True Then
            myDesignUnit = "Landscape"
        End If

        If topDir.Exists Then
            For Each subDir In topDir.GetDirectories()
                For Each bottomDir In subDir.GetDirectories
                    dirCount += subDir.GetDirectories.Length
                Next
            Next

            progDirectory.Value = 0
            progDirectory.Maximum = dirCount

            For Each subDir In topDir.GetDirectories()
                For Each bottomDir In subDir.GetDirectories
                    If progDirectory.Value < progDirectory.Maximum Then progDirectory.Value += 1

                    theseFiles = bottomDir.GetFiles("*.dgn")

                    progFile.Value = 0
                    progFile.Maximum = theseFiles.Length

                    For Each thisFile In theseFiles
                        If progFile.Value < progFile.Maximum Then progFile.Value += 1

                        row = ds.tblFiles.NewtblFilesRow
                        row.DGNFiles = thisFile.FullName  ' if you just want the file name use thisFile.Name
                        row.Directory = bottomDir.FullName ' if you just want the folder name use bottomDir.Name
                        ds.tblFiles.Rows.Add(row)
                    Next

                Next
            Next
        Else
            MsgBox("The Projects Directory was not found Contact Stephen Herrick")
        End If


    End Sub
0
 

Author Comment

by:sherrick123
ID: 13842128
Getting close.
A couple of things,
1)
Here is an example of how the directory strucute is set up
\\Engineering\Projects\Working\
                                -->>K014701
                                     -->Bridge
                                     -->Bridge Maintenance
                                     -->Landscape
                                     -->SL Structures
So from this code
        If optBridge.Checked = True Then
            myDesignUnit = "Bridge"
        ElseIf optBrgMaint.Checked = True Then
            myDesignUnit = "Bridge Maintenance"
        ElseIf optSignLight.Checked = True Then
            myDesignUnit = "SL Structures"
        ElseIf optLandScape.Checked = True Then
            myDesignUnit = "Landscape"
        End If

Is how the program know WHAT sub directory to scan for the dgn files.  Your code scan through every sub directory that has a dgn file in it.

2)
The file progress bar works great the Directory progress bar show one click and thats all


Thanks

0
 
LVL 12

Assisted Solution

by:S-Twilley
S-Twilley earned 1600 total points
ID: 13842592
Ok.. i think i see what you're trying to do now...  so i changed the code slightly (hopefully it should still work)

===============================

   Public Sub ScanDir()
        Dim myPath As String
        Dim topDir, subDir, bottomDir As DirectoryInfo
        Dim thisFile, theseFiles() As FileInfo
        Dim dirCount As Integer = 0

        Dim myDesignUnit As String

        topDir = New DirectoryInfo("\\Engineering\Projects\Working\")

        ds = New dsBridgeDGNFiles
        Dim row As dsBridgeDGNFiles.tblFilesRow

        Dim dirList As New ArrayList()

        If optBridge.Checked = True Then
            myDesignUnit = "Bridge"
        ElseIf optBrgMaint.Checked = True Then
            myDesignUnit = "Bridge Maintenance"
        ElseIf optSignLight.Checked = True Then
            myDesignUnit = "SL Structures"
        ElseIf optLandScape.Checked = True Then
            myDesignUnit = "Landscape"
        End If

        Dim thisFolder As String

        If topDir.Exists Then
            For Each subDir In topDir.GetDirectories()
                thisFolder = subDir.Fullname & myDesignUnit & "\"  ' this might need to be subDir.Fullname & "\" & myDesignUnit & "\"
                If Directory.Exists(thisFolder) Then
                    dirList.Add(thisFolder)
                End If
            Next

            progDirectory.Value = 0
            progDirectory.Maximum = dirList.Count

            For Each thisFolder in dirList
                 If progDirectory.Value < progDirectory.Maximum Then progDirectory.Value += 1
                    bottomDir = New DirectoryInfo(thisFolder)
                    If bottomDir.Exists Then
                        theseFiles = bottomDir.GetFiles("*.dgn")

                        progFile.Value = 0
                        progFile.Maximum = theseFiles.Length

                        For Each thisFile In theseFiles
                            If progFile.Value < progFile.Maximum Then progFile.Value += 1

                            row = ds.tblFiles.NewtblFilesRow
                            row.DGNFiles = thisFile.FullName  ' if you just want the file name use thisFile.Name
                            row.Directory = bottomDir.FullName ' if you just want the folder name use bottomDir.Name
                            ds.tblFiles.Rows.Add(row)
                        Next
                    End If
            Next
        Else
            MsgBox("The Projects Directory was not found Contact Stephen Herrick")
        End If

    End Sub
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 13842599
My only question is that GetDirectories is being called twice within double nested For...Next loops.  My suggestion would be to build a flat list of directories into an ArrayList the first time, and then the progress bar would be simpler to implement.

Bob
0
 

Author Comment

by:sherrick123
ID: 13842704
I nested it twice because of the way I need to recurse through the directory structure?

Here is the Example of the directory structure
\\Engineering\Projects\Working\
      K021901\     <---Project Directory
      Bridge\
      Brow\
      Coordinating\
      District\
      Enviroment\
      Geology\
      Landscape\
      Road\
      SL Structures\
      Survey\
      Traffic\

I only want to search for a ONE specific sub directory down from my project directory. per my option group
And when I search that directory I test to see if their are any files with a .dgn extension.  If it finds one then
I want to add ALL of them to my Data Source to eventually create a report.

Oh yea by the way.  This only my fifth vb .net project....

Thanks
0
 
LVL 96

Accepted Solution

by:
Bob Learned earned 400 total points
ID: 13842914
Borrowing from S-Twilley's code to highlight:

  Public Sub ScanDir()

    Dim myPath As String
    Dim thisFile, theseFiles() As FileInfo

    Dim myDesignUnit As String

    Dim topDir As DirectoryInfo = New DirectoryInfo("\\Engineering\Projects\Working\")

    ds = New dsBridgeDGNFiles
   
    If optBridge.Checked = True Then
      myDesignUnit = "Bridge"
    ElseIf optBrgMaint.Checked = True Then
      myDesignUnit = "Bridge Maintenance"
    ElseIf optSignLight.Checked = True Then
      myDesignUnit = "SL Structures"
    ElseIf optLandScape.Checked = True Then
      myDesignUnit = "Landscape"
    End If

    If topDir.Exists Then

      Dim listDirectories As New ArrayList

      For Each subDir  As DirectoryInfo In topDir.GetDirectories()
        For Each bottomDir As DirectoryInfo In subDir.GetDirectories
          listDirectories.Add(bottomDir)
        Next
      Next

      progDirectory.Value = 0
      progDirectory.Maximum = listDirectories.Count - 1

      For Each directoryCurrent As DirectoryInfo In listDirectories

        progDirectory.Value += 1

        theseFiles = directoryCurrent.GetFiles("*.dgn")

        progFile.Value = 0
        progFile.Maximum = theseFiles.Length - 1

        For Each thisFile In theseFiles
          progFile.Value += 1

          Dim row As dsBridgeDGNFiles.tblFilesRow = ds.tblFiles.NewtblFilesRow

          row.DGNFiles = thisFile.FullName  ' if you just want the file name use thisFile.Name
          row.Directory = bottomDir.FullName ' if you just want the folder name use bottomDir.Name

          ds.tblFiles.Rows.Add(row)

        Next

      Next

    Else
      MsgBox("The Projects Directory was not found Contact Stephen Herrick")
    End If

  End Sub


Bob
0

Featured Post

Prep for the ITIL® Foundation Certification Exam

December’s Course of the Month is now available! Enroll to learn ITIL® Foundation best practices for delivering IT services effectively and efficiently.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This tutorial demonstrates one way to create an application that runs without any Forms but still has a GUI presence via an Icon in the System Tray. The magic lies in Inheriting from the ApplicationContext Class and passing that to Application.Ru…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…
Whether it be Exchange Server Crash Issues, Dirty Shutdown Errors or Failed to mount error, Stellar Phoenix Mailbox Exchange Recovery has always got your back. With the help of its easy to understand user interface and 3 simple steps recovery proced…
Suggested Courses

810 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question