Results 1 to 8 of 8

Thread: Show message while progressbar is processing

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Mar 2013
    Posts
    21

    Show message while progressbar is processing

    So I want to make a Text while ProgressBar is processing. A text will show below the progressbar like. "Please wait...." then a second text if it hits the middle of the bar it will say "Verifying..." and the last text if it hits the last bar or the end will be "Complete!" something like this..

    This are my codes

    Code:
        Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
            ProgressBar1.Increment(1)
            If ProgressBar1.Value = ProgressBar1.Maximum Then
                Button2.Enabled = True
            End If
            Label2.Text = ProgressBar1.Value & (" %")
        End Sub

    Code:
        Private Sub ProgressBar1_Click(sender As Object, e As EventArgs) Handles ProgressBar1.Click
    
        End Sub
    Thanks!

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Show message while progressbar is processing

    Firstly, ProgressBars don't process anything. They just sit there showing a fraction in a fancy UI. You do the processing in code and then you set the fraction being displayed in the ProgressBar to indicate where that code is up to.

    As for the question, I'm not sure what the problem is. If you want to display a message in a Label then go ahead. You obviously know how to display text in a Label and you obviously know how to use an If statement to determine the state of the ProgressBar so what exactly is the issue?
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3
    New Member
    Join Date
    Apr 2013
    Posts
    14

    Re: Show message while progressbar is processing

    I have the same problem...

    Code:
    Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
            ProgressBar1.Increment(3)
            If ProgressBar1.Value = ProgressBar1.Maximum Then
                Timer1.Stop()
    
            End If
    
            If ProgressBar1.Value & ("1") Then
                Label1.Text = "Status: Start"
            End If
    
            If ProgressBar1.Value & ("50") Then
                Label1.Text = "Status: Bla"
            End If
    
            If ProgressBar1.Value & ("100") Then
                Label1.Text = "Status: Finished"
            End If
        End Sub
    With this code the Label only shows :" Status: Finished"

    How would be the correct syntax?

  4. #4
    Addicted Member
    Join Date
    Jan 2013
    Posts
    177

    Re: Show message while progressbar is processing

    I think the problem the both of you are having is this:

    Everything is running on the same thread, which means that the UI is not updating while the progress bar is working.

    Try running the progress bar as a background worker

    http://msdn.microsoft.com/en-CA/libr...undworker.aspx

    I dont know much on the topic but hopefully someone else chimes in

  5. #5
    New Member
    Join Date
    Apr 2013
    Posts
    14

    Re: Show message while progressbar is processing

    Quote Originally Posted by Crzyrio View Post
    I think the problem the both of you are having is this:

    Everything is running on the same thread, which means that the UI is not updating while the progress bar is working.

    Try running the progress bar as a background worker

    http://msdn.microsoft.com/en-CA/libr...undworker.aspx

    I dont know much on the topic but hopefully someone else chimes in
    I am pretty sure, that there is a more easy way than that, but thanks anyway.

    Propably there is someone else who could help me/us with that problem?

  6. #6
    PowerPoster dunfiddlin's Avatar
    Join Date
    Jun 2012
    Posts
    8,245

    Re: Show message while progressbar is processing

    Try running the progress bar as a background worker
    Well, you'd run the process as the background worker and keep the progress bar on the UI actually. I doubt that either case demands this approach but even if it does the programming of the label will be the same and it's difficult to see why there should be any problems with it.

    In cocobrico's case it's this ...

    If ProgressBar1.Value & ("1") Then

    ... which is the problem. Makes no sense. It really is very simple ...

    vb.net Code:
    1. Private Sub Timer1_Tick(sender As System.Object, e As System.EventArgs) Handles Timer1.Tick
    2.         ProgressBar1.Increment(2)
    3.         Select Case ProgressBar1.Value
    4.             Case Is < 20
    5.                 Label1.Text = "Give me a chance, I've only just started!"
    6.             Case 20 To 39
    7.                 Label1.Text = "Now we're getting somewhere!"
    8.             Case 40 To 70
    9.                 Label1.Text = "Better finish that coffee. Won't be long now."
    10.             Case 71 To 98
    11.                 Label1.Text = "Nearly there."
    12.             Case Else
    13.                 Label1.Text = "All done!"
    14.                 Timer1.Stop()
    15.         End Select
    16.     End Sub

    Having said that I'm not a fan of timer based progress bars not least because they are inherently inaccurate.
    As the 6-dimensional mathematics professor said to the brain surgeon, "It ain't Rocket Science!"

    Reviews: "dunfiddlin likes his DataTables" - jmcilhinney

    Please be aware that whilst I will read private messages (one day!) I am unlikely to reply to anything that does not contain offers of cash, fame or marriage!

  7. #7
    New Member
    Join Date
    Apr 2013
    Posts
    14

    Re: Show message while progressbar is processing

    Quote Originally Posted by dunfiddlin View Post
    Well, you'd run the process as the background worker and keep the progress bar on the UI actually. I doubt that either case demands this approach but even if it does the programming of the label will be the same and it's difficult to see why there should be any problems with it.

    In cocobrico's case it's this ...

    If ProgressBar1.Value & ("1") Then

    ... which is the problem. Makes no sense. It really is very simple ...

    vb.net Code:
    1. Private Sub Timer1_Tick(sender As System.Object, e As System.EventArgs) Handles Timer1.Tick
    2.         ProgressBar1.Increment(2)
    3.         Select Case ProgressBar1.Value
    4.             Case Is < 20
    5.                 Label1.Text = "Give me a chance, I've only just started!"
    6.             Case 20 To 39
    7.                 Label1.Text = "Now we're getting somewhere!"
    8.             Case 40 To 70
    9.                 Label1.Text = "Better finish that coffee. Won't be long now."
    10.             Case 71 To 98
    11.                 Label1.Text = "Nearly there."
    12.             Case Else
    13.                 Label1.Text = "All done!"
    14.                 Timer1.Stop()
    15.         End Select
    16.     End Sub

    Having said that I'm not a fan of timer based progress bars not least because they are inherently inaccurate.
    Thank you!! :-) It's working like charm!

  8. #8
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649

    Re: Show message while progressbar is processing

    ProgressBar1.Value & ("1") means what? The ampersand means: Put two strings together, so if the value of the ProgressBar happens to be 25 then 25 & "1" = "251" so what does the If statement:
    Code:
    If "251" Then
    means, well not much... Since you have Option Strict set to Off it means: "251" is not false so it must be true...

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width