Solved

Adding vb.net progress bar for each task in program

Posted on 2009-05-12
2
339 Views
Last Modified: 2012-05-06
I need to add a progress bar for each button's task. any help would be great. This confuses me!!!
Public Class Form1
    Public Function ExecCommand(ByRef CommandLine As String, _
                                Optional ByRef Arguments As String = "", _
                                Optional ByRef Waitforexit As Boolean = True) As Integer
        Dim psi As New ProcessStartInfo()
        Dim p As Process
 
        With psi
            .FileName = CommandLine
            .Arguments = Arguments
            .WindowStyle = ProcessWindowStyle.Hidden 'This avoid a text window being opened
        End With
        Try
            p = Process.Start(psi) 'This line runs the command
            If Waitforexit Then p.WaitForExit() 'This wait until the command ends
            Return p.ExitCode
        Catch e As System.Exception
            'Catch errors here
        End Try
    End Function
 
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim Filename1 As String
        Filename1 = TextBox1.Text
        Dim MiddleName As String
        MiddleName = TextBox1.Text.Remove(0, 4)
 
        ExecCommand("cmd", " /c " & "copy W:\" & Filename1 & " c:\CCMS\", Waitforexit:=True)
        ExecCommand("cmd", " /c " & "copy c:\ccms\" & Filename1 & " c:\ccms\archive", Waitforexit:=True)
        ExecCommand("cmd", " /c " & "rename c:\CCMS\" & Filename1 & " " & MiddleName, Waitforexit:=True)
        ExecCommand("cmd", " /c " & "dir c:\CCMS\*.mpg /o/n > c:\CCMS\FilesUploaded.txt", Waitforexit:=True)
        ExecCommand("cmd", " /c " & "c:\docume~1\" & "Administrator\Desktop\filesuploaded2.bat", Waitforexit:=True)
        ExecCommand("cmd", " /c " & "if exist c:\CCMS\FilesUploaded.txt. call c:\docume~1\Administrator\Desktop\emailCCMS.bat ELSE Exit", Waitforexit:=True)
        ExecCommand("cmd", " /c " & "move c:\ccms\" & MiddleName & " r:", Waitforexit:=True)
        
 
 
    End Sub
 
    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        Dim Filename2 As String
        Filename2 = Rename.Text
        Dim MiddleName1 As String
        MiddleName1 = NewNum.Text
 
        ExecCommand("cmd", " /c " & "copy C:\ccms\archive" & Filename2 & " c:\CCMS\", Waitforexit:=True)
        ExecCommand("cmd", " /c " & "rename c:\CCMS\" & Filename2 & " " & MiddleName1, Waitforexit:=True)
        ExecCommand("cmd", " /c " & "dir c:\CCMS\*.mpg /o/n > c:\CCMS\FilesUploaded.txt", Waitforexit:=True)
        ExecCommand("cmd", " /c " & "c:\docume~1\" & "Administrator\Desktop\filesuploaded2.bat", Waitforexit:=True)
        ExecCommand("cmd", " /c " & "if exist c:\CCMS\FilesUploaded.txt. call c:\docume~1\Administrator\Desktop\emailCCMS.bat ELSE Exit", Waitforexit:=True)
        ExecCommand("cmd", " /c " & "copy c:\ccms\" & MiddleName1 & " C:\ccms\archive", Waitforexit:=True)
        ExecCommand("cmd", " /c " & "move c:\ccms\" & MiddleName1 & " r:", Waitforexit:=True)
    End Sub
 
    Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim Filename3 As String
        Filename3 = Comcast.Text
        Dim MiddleName2 As String
        MiddleName2 = Comcast.Text.Remove(0, 4)
 
        ExecCommand("cmd", " /c " & "copy c:\CCMS\Archive\" & Filename3 & " c:\CCMS\", Waitforexit:=True)
        ExecCommand("cmd", " /c " & "rename c:\CCMS\" & Filename3 & " " & MiddleName2, Waitforexit:=True)
        ExecCommand("cmd", " /c " & "rename c:\CCMS\" & MiddleName2 & " D" & MiddleName2, Waitforexit:=True)
        ExecCommand("cmd", " /c " & "Move c:\CCMS\" & "d" & MiddleName2 & " c:\CCMS\Archive\RenamedD\", Waitforexit:=True)
        ExecCommand("cmd", " /c " & "copy c:\CCMS\Archive\RenamedD\" & "d" & MiddleName2 & " Y:\", Waitforexit:=True)
        ExecCommand("cmd", " /c " & "c:\docume~1\" & "Administrator\Desktop\febootimail.exe" & " -server 172.16.4.21 -user pat -pass D15hn3tw0rk -from ClearCut@MCVOD.COM -to marc.viste@echostar.com;hugh.selway@echostar.com;doug.davis@echostar.com;jada.yearick@echostar.com;adsalestraffic@echostar.com -subject ComCast Spots Completed -text " & "d" & MiddleName2, Waitforexit:=True)
    End Sub
 
End Class

Open in new window

0
Comment
Question by:cpservice
[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
2 Comments
 
LVL 2

Accepted Solution

by:
bootreboot earned 500 total points
ID: 24367174
If you have already added the progressbar object to your form, then the code would look something like this:
        Me.ProgressBar1.Maximum = 7
        Me.ProgressBar1.Minimum = 0
        Me.ProgressBar1.Value = 0
        ExecCommand("cmd", " /c " & "copy W:\" & Filename1 & " c:\CCMS\", Waitforexit:=True)
        Me.ProgressBar1.Value = 1
        ExecCommand("cmd", " /c " & "copy c:\ccms\" & Filename1 & " c:\ccms\archive", Waitforexit:=True)
        Me.ProgressBar1.Value = 2
        ExecCommand("cmd", " /c " & "rename c:\CCMS\" & Filename1 & " " & MiddleName, Waitforexit:=True)
        Me.ProgressBar1.Value = 3
        ExecCommand("cmd", " /c " & "dir c:\CCMS\*.mpg /o/n > c:\CCMS\FilesUploaded.txt", Waitforexit:=True)
        Me.ProgressBar1.Value = 4
        ExecCommand("cmd", " /c " & "c:\docume~1\" & "Administrator\Desktop\filesuploaded2.bat", Waitforexit:=True)
        Me.ProgressBar1.Value = 5
        ExecCommand("cmd", " /c " & "if exist c:\CCMS\FilesUploaded.txt. call c:\docume~1\Administrator\Desktop\emailCCMS.bat ELSE Exit", Waitforexit:=True)
        Me.ProgressBar1.Value = 6
        ExecCommand("cmd", " /c " & "move c:\ccms\" & MiddleName & " r:", Waitforexit:=True)
        Me.ProgressBar1.Value = 7

Open in new window

0
 
LVL 8

Expert Comment

by:RyanAndres
ID: 24367189
Execute the thread using BackgroundWorker and update the progress bar's value when the ProgressChanged event is raised.

http://msdn.microsoft.com/en-us/library/system.componentmodel.backgroundworker.aspx
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
How can I do Unit Testing with Session ? 1 23
Filtering a datagrid view 8 34
SSIS GUID Variable 2 34
reading an excel file vb.net 2 17
It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

749 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