Solved

VB.NET - Insert progress bar into loop

Posted on 2014-07-18
1
1,128 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
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

The New “Normal” in Modern Enterprise Operations

DevOps for the modern enterprise offers many benefits — increased agility, productivity, and more, but digital transformation isn’t easy, especially if you’re not addressing the right issues. Register for the webinar to dive into the “new normal” for enterprise modern ops.

Question has a verified solution.

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

The object model of .Net can be overwhelming at times – so overwhelming that quite trivial tasks often take hours of research. In this case, the task at hand was to populate the datagrid from SQL Server database in Visual Studio 2008 Windows applica…
Recently while returning home from work my wife (another .NET developer) was murmuring something. On further poking she said that she has been assigned a task where she has to serialize and deserialize objects and she is afraid of serialization. Wha…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

837 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