Solved

VB.NET - Insert progress bar into loop

Posted on 2014-07-18
1
1,025 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
Comment Utility
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

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
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 …
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

744 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now