Question Whats wrong with my Timer & Progress Bar Code?

Haxaro

Well-known member
Joined
Mar 13, 2009
Messages
105
Programming Experience
1-3
I want to make an app that gets the progress bar to 'pulse'

My code doesnt seem to work though!?!?!

VB.NET:
Public Class Form1
    Dim Value
    Dim NoValue = "Add"

    Private Sub Startbtn_clicked(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Startbtn.Click
        ProgressBar1.Value = 1
        Timer1.Enabled = True
    End Sub


    Public Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
        If NoValue = "Add" Then
            ProgressBar1.Value = Value + 1

        ElseIf NoValue = "Subtract" Then
            ProgressBar1.Value = Value - 1

        ElseIf Value = 0 Then

            ProgressBar1.Value = Value + 1
            NoValue = "Add"

        ElseIf ProgressBar1.Value = 100 Then

            ProgressBar1.Value = Value - 1
            NoValue = "Subtract"

        End If

        If Value = -1 Then
            Exit Sub
        End If
    End Sub


    Private Sub Stopbtn_clicked(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Stopbtn.Click
        Value = -1
    End Sub
End Class

I would love any help!

Thanks
 
What's wrong with it is it's in the wrong forum. Please post in the most appropriate forum for the topic, not the first one you come to. Moved.

What exactly do you mean by "pulse"? Do you mean go up and then go down and then go up, etc.? If so then this is pretty much the simplest way I can think of:
VB.NET:
Private increment As Integer = 1

Private Sub Timer1_Tick(ByVal sender As Object, _
                        ByVal e As EventArgs) Handles Timer1.Tick
    Me.ProgressBar1.Increment(Me.increment)

    Select Case Me.ProgressBar1.Value
        Case 0, 100
            Me.increment *= -1
    End Select
End Sub
You might also be interested to know that you can set the Style of a ProgressBar to Marquee to get continuous scrolling if all you want is an indicator of something happening rather than actual progress.
 
Thanks

Sorry.

Thanks! Thats works great!

Anyway i can do the same thing, just the other way, so right to left instead of left to right?

Thanks
 
Anyway i can do the same thing, just the other way, so right to left instead of left to right?
I think I tried that myself once and couldn't find a simple way to do it.
 
Back
Top