Search code examples
vb.nettimerprogress-bar

When Progressbar.value = Maximum | I Want to restart it Automatically


Please I want to restart progress bar when [Progressbar.value = Maximum] and start again automatically from 1 to 10, Without Stopping or a specific time.

this is a code

Private Sub Timer19_Tick(sender As Object, e As EventArgs) Handles Timer19.Tick

    ProgressBar11.Increment(1)
    If ProgressBar11.Value = 2 Then
        Label23.Text = "KxStpDvDe7JMpDVCZBppQaMHaGSKqn8W3xY4qDXMSdUKdxitFPGw"
    End If
    If ProgressBar11.Value = 3 Then
        Label23.Text = "KzZrERxAiZgbHopAxUtQ6iDb4SMxZbgyeDmoK8diYgDf32c9Byrg"
    End If
    If ProgressBar11.Value = 4 Then
        Label23.Text = "L2FytfFKWuWyKunmGgwjFMMhUWaTnJP7qtnKENqwnacGhV6Z2rJv"
    End If
    If ProgressBar11.Value = 5 Then
        Label23.Text = "L4aFy9gsK7jy1YpdUvgsKdHrtdg2H5YC8R9s7UFx9oHVzEoLjqxR"
    End If
    If ProgressBar11.Value = 6 Then
        Label23.Text = "L5UKKWBUDM4z49hU1XTAAF2DKy7ycPXDeTSvQXDGJoSeCDSDFQJ7"
    End If
    If ProgressBar11.Value = 7 Then
        Label23.Text = "L55RuiA6EVm7GSfoLLJD8853LUovn79MR9RzGrMD2xQqsJ25DVx5"
    End If
    If ProgressBar11.Value = 8 Then
        Label23.Text = "KxSTtoDS7Wm2P6fGaxEWui1CD4cm47hoNGaoz8am6akHpsghmV1z"
    End If
    If ProgressBar11.Value = 9 Then
        Label23.Text = "L2eJLnMRfUt3fQPqGPFAdzK1x4xA28e4hRCDbQA8Wiij4piNkyig"
    End If
        If ProgressBar11.Value = ProgressBar11.Maximum Then
        Timer19.Stop()
        Label23.Text = "KyHGgvC28cxP9HpAMz6fnB5AHJo4QxG7j2HpF8VN1SB3KuJE9zp1"
        Label27.Enabled = True
    End If
End Sub

Solution

  • Please I want to restart progress bar when [Progressbar.value = Maximum] and start again automatically from 1 to 10, Without Stopping or a specific time.

    Change:

    If ProgressBar11.Value = ProgressBar11.Maximum Then
        Timer19.Stop()
        Label23.Text = "KyHGgvC28cxP9HpAMz6fnB5AHJo4QxG7j2HpF8VN1SB3KuJE9zp1"
        Label27.Enabled = True
    End If
    

    To:

    If ProgressBar11.Value = ProgressBar11.Maximum Then
        Label23.Text = "KyHGgvC28cxP9HpAMz6fnB5AHJo4QxG7j2HpF8VN1SB3KuJE9zp1"
        Label27.Enabled = True
        ProgressBar11.Value = ProgressBar11.Minimum
    End If
    

    Though I agree with the others, there is probably much you could do to streamline your code by re-factoring it.

    Having that many Timers on your form can is going to create a ton of events that have to be processed. If the Interval on these is rather small, your application is likely to become laggy. There are other ways to accomplish multiple progressbars, possibly a datagridview with custom drawing and only ONE Timer to force the datagridview to update all "progressbars" at the same time.