Hack Forums
[.NET] [Beginners] ProgressBar [/TuT] - Printable Version

+- Hack Forums (https://hackforums.net)
+-- Forum: Tech (https://hackforums.net/forumdisplay.php?fid=444)
+--- Forum: Coding (https://hackforums.net/forumdisplay.php?fid=151)
+---- Forum: Software Development (https://hackforums.net/forumdisplay.php?fid=118)
+---- Thread: [.NET] [Beginners] ProgressBar [/TuT] (/showthread.php?tid=478565)



[Beginners] ProgressBar [/TuT] - The-One - Jun 13, 2010

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!


* - Beck - Jun 13, 2010

Nice source, mate :)

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


* - Mr. Mischief - Jun 13, 2010

i already know this...
but will save it as a snippet just incase i forget.
thanks :D


* - The-One - Jun 13, 2010

(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)bluestu10 Wrote:  i already know this...
but will save it as a snippet just incase i forget.
thanks :D

Okey. No problem