Visual Studio Development Bookmark and Share   
 index > Visual Basic Express Edition > Timer / progress bar trouble
 

Timer / progress bar trouble

Can someone help me find what I apparently can't see for myself...

I'm wanting this code to run everytime a button is clicked...
this is in the Timer1 Tick event.
        ProgressBar1.Value = i

        If i < 100 Then
            i = i + 1
        End If
        Label1.Text = "...saving " & i & " %"

        If i = 100 Then
            ccls.frm2save()
            Timer1.Stop()


        End If
on the page load I've put:

Timer1.interval = 10
timer1.enabled = false


and on the button click
timer1.start()


Weellll....the code works great the first time, but if I click the button a second time...it does nothing.

What is it that I'm overlooking?
mreed72  Friday, October 16, 2009 5:08 PM
if you want it to run with each Button Click

reset i to 0 in the button click event


Dim i As Integer
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        i = 0
        Timer1.Enabled = True
        Timer1.Interval = 250
    End Sub

    Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
        If Not i > 100 Then
            Label1.Text = "...saving " & i & " %"
        Else
            Timer1.Enabled = False
        End If
        i += 1
    End Sub
  • Proposed As Answer byRudedog2 Friday, October 16, 2009 5:29 PM
  • Marked As Answer bymreed72 Friday, October 16, 2009 5:35 PM
  •  
jwavila  Friday, October 16, 2009 5:28 PM
Where do initialize/reset the variable " i "?

Mark the best replies as answers. "Fooling computers since 1971."
Rudedog2  Friday, October 16, 2009 5:12 PM
sry about that....  I just DIM "i" under the Public Class as Integer

Public Class Form2
    Dim i As Integer


' code

End Class


mreed72  Friday, October 16, 2009 5:13 PM
if you want it to run with each Button Click

reset i to 0 in the button click event


Dim i As Integer
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        i = 0
        Timer1.Enabled = True
        Timer1.Interval = 250
    End Sub

    Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
        If Not i > 100 Then
            Label1.Text = "...saving " & i & " %"
        Else
            Timer1.Enabled = False
        End If
        i += 1
    End Sub
  • Proposed As Answer byRudedog2 Friday, October 16, 2009 5:29 PM
  • Marked As Answer bymreed72 Friday, October 16, 2009 5:35 PM
  •  
jwavila  Friday, October 16, 2009 5:28 PM
Thanks, I see now how that works.  In my ccls.frm2save()  I was resetting the progressbar value to 0 but not the "i".

I put:

i = 0

in the button click event and it works like intended.

thank you

mreed72  Friday, October 16, 2009 5:38 PM

You can use google to search for other answers

Custom Search

More Threads

• installer/.exe file question...
• How can I make this faster !!?
• Itunes style reflections
• how to remove SQL Server ?
• New to Visual Basic Express - Viewing and Printing Data
• My Web Browser "The Web Browser Project"
• Info on Microsoft Install Fest
• How to create video and audio chat in vb.net
• Need help with Sub statement
• Conversion from type 'String()' to type 'String' is not valid.