Results 1 to 8 of 8

Thread: How to do Progress Bar?

  1. #1

    Thread Starter
    Member
    Join Date
    Sep 2008
    Location
    South-Africa
    Posts
    49

    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?

  2. #2
    Addicted Member Zero2Cool's Avatar
    Join Date
    Aug 2006
    Location
    Green Bay, WI
    Posts
    203

    Re: How to do Progress Bar?

    This should help you out a great deal.
    http://msdn.microsoft.com/en-us/libr...ar(VS.80).aspx

  3. #3
    Frenzied Member
    Join Date
    Sep 2006
    Location
    UK / East Sussex
    Posts
    1,054

    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?
    M.Carpenter

    Server Admin for Wurm Online
    Wurm Online - A very unique and original MMO from Code Club AB
    https://www.youtube.com/watch?v=YQlYar2uHWAWurm Trailor


  4. #4

    Thread Starter
    Member
    Join Date
    Sep 2008
    Location
    South-Africa
    Posts
    49

    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.

  5. #5

    Thread Starter
    Member
    Join Date
    Sep 2008
    Location
    South-Africa
    Posts
    49

    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?

  6. #6
    Addicted Member Zero2Cool's Avatar
    Join Date
    Aug 2006
    Location
    Green Bay, WI
    Posts
    203

    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.

  7. #7
    Frenzied Member
    Join Date
    Sep 2006
    Location
    UK / East Sussex
    Posts
    1,054

    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
    M.Carpenter

    Server Admin for Wurm Online
    Wurm Online - A very unique and original MMO from Code Club AB
    https://www.youtube.com/watch?v=YQlYar2uHWAWurm Trailor


  8. #8

    Thread Starter
    Member
    Join Date
    Sep 2008
    Location
    South-Africa
    Posts
    49

    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
  •  



Click Here to Expand Forum to Full Width