I've got a little issue with a progress bar.I have a label and the progress bar on a form.I've some calculation to be performed and then stored to the database.I wanted to show the progress of this process to the user.The calculation process is on another form.when the process starts i displayed the form but it shows the progress after the records are saved to the database.
How can i achieve this along with the calculation?Here are the codes i used.

The code below calls a procedure to read records from an excel file,then calls another procedure to perform the calculation on a row basis:

 Public Sub importToDb(ByVal district As String)
        dt = New DataTable
        Windows.Forms.Cursor.Current = Cursors.WaitCursor
        dt = ReadExcel(district)
        total = dt.Rows.Count

        For i = 0 To dt.Rows.Count - 1
            If Not IsDBNull(dt.Rows(i)(0)) Then
                calculatesave(i, district)
            End If

        dt = Nothing
    End Sub

This is the code related to the progress bar in another form,placed in a timer tick event:

Me.ProgressBar1.Maximum = frmBridge.total

        If Me.ProgressBar1.Value >= Me.ProgressBar1.Maximum Then
            MessageBox.Show("Importing Successful")
            Me.ProgressBar1.Value = Me.ProgressBar1.Value + 1
            Label1.Text = "Importing " & Me.ProgressBar1.Value & " of " & Me.ProgressBar1.Maximum
        End If

You don't need to use a timer to update the progress bar. Just increment the progressbar value in the loop you are tracking. As for the cross form update, why not just put the progress bar on the form containing the loop?

I agree with Jim. Incrementing the progress bar value is much easier since you are performing the calculations to determine the progress of your task. To do this, try incrementing like so:


Of course you would not use +1 but change it to cater to your needs.

Edited 2 Years Ago by NetJunkie

I just needed to show it separately,just for a design purpose.Of course it works well on the form holding the loop but just for the record,is it possible or not?

This question has already been answered. Start a new discussion instead.