Re: How to do Progress Bar?
Re: How to do Progress Bar?
Hi, I don't know if you have managed to do this yet as you havn't replied but on the Designer Form just use the toolbox and add a button, a timer and a progress bar.
Give them useful names using the properties box (by default on the right) for each object.
Next in the code of the button just use the 'timername.Start()' event that will start the timer off
The in the Timer Fire Event just use the ProgressBarName.Value command and you can either = value or do something like:
ProgressBarName.Value = ProgressBarName.Value + 2
With that code each time the Timer Fire Event happens the progress bar will plus two to its current value however you will need to add a check to make sure the Progress Bar's value doesn't go over 100 or else the program will bomb out with an error. That can easily be done with something like
If ProgressBarName.Value = 100 then
TimerName.Stop()
End If
Does this help?
Re: How to do Progress Bar?
yes it did... thanks man... I need to learn small little stuff like this... but didnt get timer to work... im using VB2005...
Re: How to do Progress Bar?
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Timer1.Start()
If ProgressBar1.Value = 100 Then
Timer1.Stop()
End If
End Sub
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
Me.ProgressBar1.Value = ProgressBar1.Value + 2
End Sub
this is what I have... is this correct?
Re: How to do Progress Bar?
You might want the IF statement in the timer_tick event. It won't be processed in the button click event and might cause an error.
Re: How to do Progress Bar?
No not Exactly. Without doing it for you because I believe its important for learning to be able to do it yourself and understand it. There are two routines that are important to you,
1: The Button Click Event
2: The Timer Fire Event
In the Button Click Event all you need is to start up the timer
In the Timer Fire Event You need code to add up the progress bar and code to check the progress and stop the timer where nessary.
The Button Click Event will begin with something like this if you let VB do the code for you:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
The timer will look something like this:
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
The method I use to add up the progress bar like this would be:
Progressbar1.value = ProgressBar1.valuie + 2
Then the code to check if its at 100 or not and stop the timer if it is.
Something to take notice of is that the timer has a property called 'Interval' this specfies how often the Timer Fire Event happens and is measure in Milliseconds.
The Default value for this property is 100 meaning it will fire 10 times every second
The reason I am mentioning this is if you set the value to say something like 30000 which means it will fire once every 30 seconds the first fire will not happen as soon as you start time timer the first fire would happen 30 seconds after you started the timer. So take that into consideration.
Regards,
Max
Re: How to do Progress Bar?
got it to work... thanks to both you guys... I had the If in the timer click, but what I did was click on button1 again after it had stopped... this causes an error... thanks again!