Home Upgrade Search Memberlist Extras Hacker Tools Award Goals Help Wiki Contact

.NET 

[Beginners] ProgressBar [/TuT]

Hello people!

Today i'm going to teach you beginners in vb.net how to make a progress bar.

Needs:
- Visual basic 2008/2010
- New Project
- 1 Form

What are we going to do?

I'm going to make the progressbar show values and when it reach's a value it pops a message box with the time (in seconds) how long it took to reach the value.

Okey, this is my GUI:
[img]http://i48.[censored].com/126bnd3.png[/img] (ALSO ADD A TIMER! )

Coding:

Double click the button1(Text=Start):
Code
If Timer1.Enabled = False Then ' If the timer isn't running do:
    Timer1.Start() ' Start the timer
    Button1.Text = "Stop" ' Change buttons text from start to stop
  Else ' If it is running do:
    Timer1.Stop() ' Stop the timer
    Button1.Text = "Start" ' Change buttons text from stop to start
    ProgressBar1.Value = 0 ' Change the progressbar's value to 0*
  End If
*= Make the progressbar's maximum value 10, if you can't find it, add ProgressBar1.Maximum = 10 to form1.load

Next, Form1.Load:
Code
' This is what we are going to use as a count system
Label1.Text = "0"
Label2.Text = "0"

After that, double click the timer (Timers interval= 500):
Code
Dim Nmr As Integer = 0 ' Define a integer
  ProgressBar1.Value = GRN(1, 11) ' Generate a random value
  Label1.Text = Label1.Text + 1 ' Count + 1
  If Label1.Text = 2 Then ' If count = 2 (500*2=1000 = 1 SEC)
    Label1.Text = 0 ' Count = 0 (restart counting)
    Label2.Text = Label2.Text + 1 ' Seconds + 1
  End If
  If ProgressBar1.Value = 10 Then ' If its 10
    Timer1.Stop() ' Stop the timer
    MsgBox("Maximum Reached In: " & Label2.Text & " Secconds.") 'Draw a message with the message and the secconds
  End If

And if u did it all right, you got 1 error at the GRN(GenerateRandomNumber)(Add this somewhere in your form class):
Code
Public Function GRN(ByVal min As String, ByVal max As String)
  Dim RD As New Random() ' Define RD as random class
  Dim RN As Integer ' Define Rn as a integer
  RN = RD.Next(min, max) ' Randomize a number between min & max
  Return RN ' Return the randomized number
    End Function

Full Source:
Spoiler (Click to View)

Enjoy!
Rate,Comment etc. etc!
FR1908
Nice source, mate :)

😉 I will check it out later if I ever get the time to.
i already know this...
but will save it as a snippet just incase i forget.
thanks :D
(Jun 13, 2010 09:33 AM)Beck Wrote:  Nice source, mate :)

😉 I will check it out later if I ever get the time to.

Thanks, good luck.

(Jun 13, 2010 09:36 AM)Mr. Mischief Wrote:  i already know this...
but will save it as a snippet just incase i forget.
thanks :D

Okey. No problem
FR1908


Possibly Related Threads...
Thread / Author Replies Views Last Post
[.NET] by elmagekOct 24, 2021 02:50 PM 7 288 Oct 24, 2021 02:50 PM
Last Post: #Kat
[.NET] by DeStilleGastJul 4, 2016 03:09 AM 3 427 Jul 4, 2016 03:09 AM
Last Post: DeStilleGast
[C#] by AspectModdingMar 28, 2016 12:43 PM 4 237 Mar 28, 2016 12:43 PM
Last Post: th3s3cr3t0n3