Adding a repeating progress bar in Microsoft Visual Basic (VB) can make your application more user-friendly; it communicates to the user that the application is working in the background. A progress bar control visually indicates the progress of a lengthy operation by showing a continuous bar that fills in from left to right. You can continuously show the same progress bar repeating itself by using a "While...Loop" and changing the value of the progress bar.
- Skill level:
Things you need
- Microsoft Visual Studio
Launch Microsoft Visual Studio, click "New Project" from the left pane of your computer screen, and expand "Visual Basic" below "Installed Templates." Click "Windows" and double-click "Windows Forms Application" from the centre of the dialogue window to create a new project.
Double-click "ProgressBar" from the "Toolbox" pane to add a new progress bar control. Double-click "Button" to add a new button to the form. Add a second button.
Double-click "Button1" to create a new button click event. Add the following code to create a loop to repeat the progress bar until the user clicks the second button:
Dim xCntr As Integer
xCntr = 1 userWantsToStop = False Me.ProgressBar1.Minimum = 0 Me.ProgressBar1.Maximum = 1000 Do While (userWantsToStop = False) Me.ProgressBar1.Value = xCntr Application.DoEvents() System.Threading.Thread.Sleep(1) If (xCntr = 1000) Then xCntr = 1 End If xCntr = xCntr + 1 Loop
Switch back to Form Design view and double-click "Button2" to create a click event for this button. Add the following code to reset the progress bar and stop the while loop in the previous step:
userWantsToStop = True
Me.ProgressBar1.Value = 0
Press "F5" to run the program and click "Button1" to start repeating the progress bar. Click "Button2" to stop it.
- 20 of the funniest online reviews ever
- 14 Biggest lies people tell in online dating sites
- Hilarious things Google thinks you're trying to search for