Solved

VB.NET - Insert progress bar into loop

Posted on 2014-07-18
1
1,189 Views
Last Modified: 2014-08-19
I've been asked to quickly run up a application that creates a text file of computers in an OU and then loops through each line to reboot them one by one.

I would really like to show a progress bar to give a visual indication but I've never done one of these before:

Here's my existing code:
Try
                    Dim str2 As String = File.OpenText(text).ReadLine
                    Dim reader2 As New StreamReader(text)
                    
                    Do While Not reader2.EndOfStream
                            str2 = reader2.ReadLine
                            Process.Start("C:\Windows\System32\shutdown.exe", " /m \\" & str2 & " /r /t 2 /d p:0:0")
                            Threading.Thread.Sleep(6000)
                            
                    Loop
                Catch ex As SystemException
                    MsgBox(ex.Message)
                End Try

Open in new window


Can anyone show me how to get "ProgressBar1" into this loop please?
0
Comment
Question by:fruitloopy
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 21

Accepted Solution

by:
Randy Poole earned 500 total points
ID: 40204394
In this example the progressbar is named PB on the form:
        Dim str2 As String
        Dim file As New FileInfo(Text)
        Dim sB As Long = file.Length
        Dim cR As Long = 0
        PB.Maximum = 100

        Dim reader2 As New StreamReader(Text)
        Try
            Do While Not reader2.EndOfStream
                str2 = reader2.ReadLine
                cR = cR + str2.Length
                PB.Value = (cR / sB) * 100
                Application.DoEvents()
                Process.Start("C:\Windows\System32\shutdown.exe", " /m \\" & str2 & " /r /t 2 /d p:0:0")
                Threading.Thread.Sleep(6000)
            Loop
        Catch ex As SystemException
            MsgBox(ex.Message)
        End Try

Open in new window

0

Featured Post

Enroll in May's Course of the Month

May’s Course of the Month is now available! Experts Exchange’s Premium Members and Team Accounts have access to a complimentary course each month as part of their membership—an extra way to increase training and boost professional development.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
How do I bind a WPF ComboBox to an ItemSource using XAML? 2 47
Visual Studio npm 1 39
Call to SQL server times out 5 55
Need a quick overview of Selenium testing 2 35
In my previous two articles we discussed Binary Serialization (http://www.experts-exchange.com/A_4362.html) and XML Serialization (http://www.experts-exchange.com/A_4425.html). In this article we will try to know more about SOAP (Simple Object Acces…
Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
Finding and deleting duplicate (picture) files can be a time consuming task. My wife and I, our three kids and their families all share one dilemma: Managing our pictures. Between desktops, laptops, phones, tablets, and cameras; over the last decade…

734 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question