|
-
Sep 24th, 2008, 07:01 AM
#1
Thread Starter
Member
How to do Progress Bar?
I am really new with VB, only started a course 3 months ago... dont like the search engine VB provides, shows way to advanced stuff for me till date... anyone just have some code where you click on button and it activates a timer and runs a progressbar till its full and stops?
-
Sep 24th, 2008, 07:07 AM
#2
Addicted Member
Re: How to do Progress Bar?
-
Sep 24th, 2008, 07:28 AM
#3
Frenzied Member
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?
-
Sep 24th, 2008, 07:34 AM
#4
Thread Starter
Member
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...
Last edited by Switch_639; Sep 24th, 2008 at 07:38 AM.
-
Sep 24th, 2008, 07:46 AM
#5
Thread Starter
Member
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?
-
Sep 24th, 2008, 08:01 AM
#6
Addicted Member
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.
-
Sep 24th, 2008, 08:17 AM
#7
Frenzied Member
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
-
Sep 24th, 2008, 08:26 AM
#8
Thread Starter
Member
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!
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|