Solved

VB.NET - Insert progress bar into loop

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

A basic question.. “What is the Garbage Collector?” The usual answer given back: “Garbage collector is a background thread run by the CLR for freeing up the memory space used by the objects which are no longer used by the program.” I wondered …
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
In this video I am going to show you how to back up and restore Office 365 mailboxes using CodeTwo Backup for Office 365. Learn more about the tool used in this video here: http://www.codetwo.com/backup-for-office-365/ (http://www.codetwo.com/ba…

910 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

21 Experts available now in Live!

Get 1:1 Help Now