locked
Progress Bar RRS feed

  • Question

  • Hello All,

    I am in the process of writing a program that will install Fonts on windows, as well as run several Batch files to install software as well. I am stumped when it comes to a progress bar. I have been searching for weeks tring to find an answer so i am hopping that some one he can help.

    I need to get this program to show the progress of the installs based on which items were selected on the Previous screen. For example, a user can install up to 25 things. If they only select 10 I want it to show the progress of the ten that are selected and two progresses. One for the Item its self and the overall progress of all them Items. Is that possible to do that. By the way i am am runiv VB 2010 Express.

    If you can help I would appreciate it. I am an abolute Novice on the Progress bar programming So a walk trough will be greatly appreciated. Thank you

    Monday, October 8, 2012 10:44 PM

Answers

  • Hi ProfessionalNewbie,

    first of all welcome in this forum.

    To your question. It is allmost the same procedure.
    Count how many Items are selected for you process.
    Divide this numer by 100 and you'll receice aproxiamtely the procentual size of each item. E.g the user seltec 20 items (100/20 = 5) ech item is 5%. Does the user select only 5 items (100/5 = 20) each item represents 20%

    Declare this result a variable type double because  100/6 = 16.666 which ask a double variable.
    Start copying files in a for next or for each loop and increase your progressbar value by this variable.
    Of course there also exist more confortable methods but this should work also fine.


    Liebe Grüße Stefan | Cheers Stefan I'm using VB 2008 and VB 2010 Express Be a good forum member - mark posts that contain the answers to your questions or those that are helpful. c# in vb Translator: http://www.developerfusion.com/tools/convert/csharp-to-vb/

    Tuesday, October 9, 2012 2:25 PM
  • Hi ProfessionalNewbie,

    Here is a sample made for you. If you want test the code, create a new application, and add a processbar, a button and a Timer to the Form.

    The example uses the Minimum and Maximum properties to specify a range for the ProgressBar that is equivalent to the number of Fonts to install. The code also uses the Step property with the PerformStep method to increment the value of the ProgressBar as a Font is installed.  Add the Timer to used for invoke the PerformStep method (you also need to create a new method to instead the Timer.tick event to invoke the PerformStep method).

    Here is the code:

    Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
            'Set the Max number whitch is the all the Fonts to be installed
            ProgressBar1.Maximum = 20
            ProgressBar1.Minimum = 1
            ' Set the initial value of the ProgressBar.
            ProgressBar1.Value = 1
            ' Set the Step property to a value of 1 to represent each file being installed.
            ProgressBar1.Step = 1
            Timer1.Start()
        End Sub
        Private Sub Timer1_Tick(sender As System.Object, e As System.EventArgs) Handles Timer1.Tick
            ProgressBar1.PerformStep()
            If ProgressBar1.Value = ProgressBar1.Maximum Then
                Timer1.Stop()
                MessageBox.Show("Finished!")
            End If
        End Sub

    Hope this helps.


    Mark Liu-lxf [MSFT]
    MSDN Community Support | Feedback to us

    Wednesday, October 10, 2012 3:15 AM
    Moderator
  • Of course i can. But not complete. Finally it's your project ;-)

    Imports System.IO
    Imports System.Text
    Imports System
    Imports Microsoft.VisualBasic
    
    Public Class Form1
        Public SelFile As String
        Public counter
        Public ProgressBarQuotient As Double
    
    
    
        Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
            Try
                If Me.FolderBrowserDialog1.ShowDialog = Windows.Forms.DialogResult.OK Then
    
                    SelFile = Me.FolderBrowserDialog1.SelectedPath
                    counter = My.Computer.FileSystem.GetFiles(SelFile)
                    Me.Label1.Text = SelFile
                    Me.Label2.Text = "number of files is " & CStr(counter.Count)
                    ProgressBarQuotient = (100 / CStr(counter.Count))
    
                    If CStr(counter.Count) > 0 Then
                        Me.Label3.Text = "Quotient = " & ProgressBarQuotient
                    Else
                        MsgBox("Selected Folder does not contain any files!", MsgBoxStyle.Information)
                    End If
    
                End If
            Catch ex As Exception
                MsgBox("Any mistake", MsgBoxStyle.Critical)
            End Try
        End Sub
    
        Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            Me.Label1.Text = ""
            Me.Label2.Text = ""
            Me.Label3.Text = ""
            Me.ProgressBar1.Minimum = 0
            Me.ProgressBar1.Maximum = 100
            Me.ProgressBar1.Value = 0
            Me.ProgressBar1.Visible = False
        End Sub
    
        Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
            Me.ProgressBar1.Visible = True
            Dim Destination As String = "C:\Giftzwockel"
            Me.ProgressBar1.Value = Me.ProgressBar1.Value + ProgressBarQuotient
    
            'Start copying here
    
        End Sub
    
    End Class
    

    The only thing to do is copy all files from your selected folder to the destination folder.
    I'm sure you'll solve this your own.
    So far you need 2 Buttons

    3 Labels

    1 ProgressBar

    Good luck


    Liebe Grüße Stefan | Cheers Stefan I'm using VB 2008 and VB 2010 Express Be a good forum member - mark posts that contain the answers to your questions or those that are helpful. c# in vb Translator: http://www.developerfusion.com/tools/convert/csharp-to-vb/

    Thursday, October 11, 2012 6:09 PM

All replies

  • Hi ProfessionalNewbie,

    first of all welcome in this forum.

    To your question. It is allmost the same procedure.
    Count how many Items are selected for you process.
    Divide this numer by 100 and you'll receice aproxiamtely the procentual size of each item. E.g the user seltec 20 items (100/20 = 5) ech item is 5%. Does the user select only 5 items (100/5 = 20) each item represents 20%

    Declare this result a variable type double because  100/6 = 16.666 which ask a double variable.
    Start copying files in a for next or for each loop and increase your progressbar value by this variable.
    Of course there also exist more confortable methods but this should work also fine.


    Liebe Grüße Stefan | Cheers Stefan I'm using VB 2008 and VB 2010 Express Be a good forum member - mark posts that contain the answers to your questions or those that are helpful. c# in vb Translator: http://www.developerfusion.com/tools/convert/csharp-to-vb/

    Tuesday, October 9, 2012 2:25 PM
  • Could you possibly give me coding examples of how to get this done. I am having a hard time getting the Progress bar to work.
    Tuesday, October 9, 2012 9:51 PM
  • Hi ProfessionalNewbie,

    Here is a sample made for you. If you want test the code, create a new application, and add a processbar, a button and a Timer to the Form.

    The example uses the Minimum and Maximum properties to specify a range for the ProgressBar that is equivalent to the number of Fonts to install. The code also uses the Step property with the PerformStep method to increment the value of the ProgressBar as a Font is installed.  Add the Timer to used for invoke the PerformStep method (you also need to create a new method to instead the Timer.tick event to invoke the PerformStep method).

    Here is the code:

    Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
            'Set the Max number whitch is the all the Fonts to be installed
            ProgressBar1.Maximum = 20
            ProgressBar1.Minimum = 1
            ' Set the initial value of the ProgressBar.
            ProgressBar1.Value = 1
            ' Set the Step property to a value of 1 to represent each file being installed.
            ProgressBar1.Step = 1
            Timer1.Start()
        End Sub
        Private Sub Timer1_Tick(sender As System.Object, e As System.EventArgs) Handles Timer1.Tick
            ProgressBar1.PerformStep()
            If ProgressBar1.Value = ProgressBar1.Maximum Then
                Timer1.Stop()
                MessageBox.Show("Finished!")
            End If
        End Sub

    Hope this helps.


    Mark Liu-lxf [MSFT]
    MSDN Community Support | Feedback to us

    Wednesday, October 10, 2012 3:15 AM
    Moderator
  • Mark Liu-lxf, I doubt that a timer is appropriate for this problem.  There are a known number of tasks but no knowledge of their duration or data volume (font installs and batch file processes).  So task completion would be the proper place to increment the progress bar. 

    As for the OP, the lack of knowledge regarding volume or time certainly precludes a two progress bar solution.  The only thing known is the number of tasks and how many are completed.  Even though any task may take many times the amount of time to process as any other task, not knowing this leaves you with little choice but a single progress bar which, in this case, is no different than a counter.  There is nothing upon which to base an ETC either.

    Wednesday, October 10, 2012 4:17 PM
  • Of course i can. But not complete. Finally it's your project ;-)

    Imports System.IO
    Imports System.Text
    Imports System
    Imports Microsoft.VisualBasic
    
    Public Class Form1
        Public SelFile As String
        Public counter
        Public ProgressBarQuotient As Double
    
    
    
        Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
            Try
                If Me.FolderBrowserDialog1.ShowDialog = Windows.Forms.DialogResult.OK Then
    
                    SelFile = Me.FolderBrowserDialog1.SelectedPath
                    counter = My.Computer.FileSystem.GetFiles(SelFile)
                    Me.Label1.Text = SelFile
                    Me.Label2.Text = "number of files is " & CStr(counter.Count)
                    ProgressBarQuotient = (100 / CStr(counter.Count))
    
                    If CStr(counter.Count) > 0 Then
                        Me.Label3.Text = "Quotient = " & ProgressBarQuotient
                    Else
                        MsgBox("Selected Folder does not contain any files!", MsgBoxStyle.Information)
                    End If
    
                End If
            Catch ex As Exception
                MsgBox("Any mistake", MsgBoxStyle.Critical)
            End Try
        End Sub
    
        Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            Me.Label1.Text = ""
            Me.Label2.Text = ""
            Me.Label3.Text = ""
            Me.ProgressBar1.Minimum = 0
            Me.ProgressBar1.Maximum = 100
            Me.ProgressBar1.Value = 0
            Me.ProgressBar1.Visible = False
        End Sub
    
        Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
            Me.ProgressBar1.Visible = True
            Dim Destination As String = "C:\Giftzwockel"
            Me.ProgressBar1.Value = Me.ProgressBar1.Value + ProgressBarQuotient
    
            'Start copying here
    
        End Sub
    
    End Class
    

    The only thing to do is copy all files from your selected folder to the destination folder.
    I'm sure you'll solve this your own.
    So far you need 2 Buttons

    3 Labels

    1 ProgressBar

    Good luck


    Liebe Grüße Stefan | Cheers Stefan I'm using VB 2008 and VB 2010 Express Be a good forum member - mark posts that contain the answers to your questions or those that are helpful. c# in vb Translator: http://www.developerfusion.com/tools/convert/csharp-to-vb/

    Thursday, October 11, 2012 6:09 PM
  • Hi ProfessionalNewbie,

    We haven’t heard from you for several days. I’d like to mark the helpful reply as answers firstly. If you have any additional questions, you also can unmark the replay and post your question here. 

    Sorry for any inconvenience and have a nice day.


    Mark Liu-lxf [MSFT]
    MSDN Community Support | Feedback to us

    Wednesday, October 17, 2012 5:26 AM
    Moderator