VB.Net Progress Bar

andyb7901
andyb7901 used Ask the Experts™
on
Hey,
Can someone tell me how I can use the progress bar thingy? I have a search that runs that takes a while. While this is running is it possible to have the progress bar ticking over?
Thanks
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Ryan ChongSoftware Team Lead

Commented:
try set the Progress Bar's Style to Marquee, like:

ProgressBar1.Style = ProgressBarStyle.Marquee
        ProgressBar1.MarqueeAnimationSpeed = 30

Author

Commented:
How would I make it run though? I have the following code to do a search. While the search ir running i would like the progress bar to run as well? Can this be done?

    Private Sub SearchForFiles(ByVal StartDir As String)
        Dim DirPath As String = Path.GetDirectoryName(StartDir)
        Dim FilePattern As String = Path.GetFileName(StartDir)
        FilePattern = "*" & FilePattern & "*"
        Dim TotalFiles As Integer = 0
        lstResults.Items.Clear()
        If Directory.Exists(DirPath) Then
            Dim di As New DirectoryInfo(DirPath)
            Dim fi() As FileInfo = di.GetFiles(FilePattern, SearchOption.AllDirectories)
            For Each f As FileInfo In fi
                lstResults.Items.Add(f.FullName)
                TotalFiles += 1
            Next
        Else
            lstResults.Items.Add("Invalid Start Directory")
        End If
        lstResults.Items.Add("Total Files = " & TotalFiles.ToString())
    End Sub
Software Team Lead
Commented:
perhaps:


Private Sub SearchForFiles(ByVal StartDir As String)
        Dim DirPath As String = Path.GetDirectoryName(StartDir)
        Dim FilePattern As String = Path.GetFileName(StartDir)
        FilePattern = "*" & FilePattern & "*"
        Dim TotalFiles As Integer = 0
        lstResults.Items.Clear()
        If Directory.Exists(DirPath) Then
            Dim di As New DirectoryInfo(DirPath)
            Dim fi() As FileInfo = di.GetFiles(FilePattern, SearchOption.AllDirectories)
            For Each f As FileInfo In fi
                lstResults.Items.Add(f.FullName)
                TotalFiles += 1

ProgressBar1.value += 1
Application.DoEvents()

if ProgressBar1.value = ProgressBar1.Maximum Then ProgressBar1.value = ProgressBar1.Minimum

            Next
        Else
            lstResults.Items.Add("Invalid Start Directory")
        End If
        lstResults.Items.Add("Total Files = " & TotalFiles.ToString())
    End Sub
Ensure you’re charging the right price for your IT

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden using our free interactive tool and use it to determine the right price for your IT services. Start calculating Now!

Luan JubicaProject Manager
Commented:
Private Sub SearchForFiles(ByVal StartDir As String)
        Dim DirPath As String = Path.GetDirectoryName(StartDir)
        Dim FilePattern As String = Path.GetFileName(StartDir)
        FilePattern = "*" & FilePattern & "*"
        Dim TotalFiles As Integer = 0
        lstResults.Items.Clear()
        If Directory.Exists(DirPath) Then
              Dim di As New DirectoryInfo(DirPath)
            Dim fi() As FileInfo = di.GetFiles(FilePattern, SearchOption.AllDirectories)
    ProgressBar1.Maxvalue=fi.count
            For Each f As FileInfo In fi
                lstResults.Items.Add(f.FullName)
                TotalFiles += 1
                ProgressBar1.value=TotalFiles
            Next
        Else
            lstResults.Items.Add("Invalid Start Directory")
        End If
        lstResults.Items.Add("Total Files = " & TotalFiles.ToString())
    End Sub
             

Author

Commented:
Im sorry to screw you around my code has changed? Could you tell me how to do it for my new code? Or shall I open a new question?
Luan JubicaProject Manager

Commented:
I think you should open another question, but anyway what happened to your code??????

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial