Results 1 to 37 of 37

Thread: [2008] Progress Bar

  1. #1

    Thread Starter
    Lively Member Colin Dias's Avatar
    Join Date
    Jan 2008
    Posts
    99

    [2008] Progress Bar

    Can someone post some code on how the progress bar will work when the login screen is loading up ?

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

    Re: [2008] Progress Bar

    All ProgressBars work the same way. Either you call the PerformStep method or you set the Value property explicitly. The ProgressBar has no specific connection to any task. It's completely up to you to perfrom all the mathematics required to determine what the actual progress is, then update the control to display the appropriate value to the user.
    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

    Thread Starter
    Lively Member Colin Dias's Avatar
    Join Date
    Jan 2008
    Posts
    99

    Re: [2008] Progress Bar

    I dont know how to do that

  4. #4
    Hyperactive Member cameron2's Avatar
    Join Date
    Mar 2008
    Location
    Australia
    Posts
    401

    Re: [2008] Progress Bar

    Here is some code so that when your form has loaded your progress bar will be filled gradually, just put this where you want.
    Code:
     Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            ProgressBar1.PerformStep()
            System.Threading.Thread.Sleep(100)
            ProgressBar1.PerformStep()
            System.Threading.Thread.Sleep(100)
            ProgressBar1.PerformStep()
            System.Threading.Thread.Sleep(100)
            ProgressBar1.PerformStep()
            System.Threading.Thread.Sleep(100)
            ProgressBar1.PerformStep()
            System.Threading.Thread.Sleep(100)
            ProgressBar1.PerformStep()
            System.Threading.Thread.Sleep(100)
            ProgressBar1.PerformStep()
            System.Threading.Thread.Sleep(100)
            ProgressBar1.PerformStep()
            System.Threading.Thread.Sleep(100)
            ProgressBar1.PerformStep()
            System.Threading.Thread.Sleep(100)
            ProgressBar1.PerformStep()
    
        End Sub

  5. #5
    Raging swede Atheist's Avatar
    Join Date
    Aug 2005
    Location
    Sweden
    Posts
    8,018

    Re: [2008] Progress Bar

    Why would anyone want to sleep the UI thread? Besides, since the Load event is raised before the form shows, you're not going to see the progressbar do anything, you will just delay the form showing by ~1 second from putting the UI thread to sleep.
    Rate posts that helped you. I do not reply to PM's with coding questions.
    How to Get Your Questions Answered
    Current project: tunaOS
    Me on.. BitBucket, Google Code, Github (pretty empty)

  6. #6

    Thread Starter
    Lively Member Colin Dias's Avatar
    Join Date
    Jan 2008
    Posts
    99

    Re: [2008] Progress Bar

    It doesnt work, on running the program, the progress bar is already filled up. And it just stays that way till the next form shows up.

  7. #7
    Raging swede Atheist's Avatar
    Join Date
    Aug 2005
    Location
    Sweden
    Posts
    8,018

    Re: [2008] Progress Bar

    You'd need to have something measureable in your code in order to have use of a ProgressBar. Dont just smack one on to your form and "fake" it like cameron2 showed you, its silly and serves no purpose.
    Are you doing something particular during the loading of your login form?
    Rate posts that helped you. I do not reply to PM's with coding questions.
    How to Get Your Questions Answered
    Current project: tunaOS
    Me on.. BitBucket, Google Code, Github (pretty empty)

  8. #8
    Hyperactive Member cameron2's Avatar
    Join Date
    Mar 2008
    Location
    Australia
    Posts
    401

    Re: [2008] Progress Bar

    Yes i realise that it is a really stupid way to use a progress bar but i was just giving him an example and since i had no idea of what he wanted to use his progress bar to measure i couldn't give him an example.

  9. #9

    Thread Starter
    Lively Member Colin Dias's Avatar
    Join Date
    Jan 2008
    Posts
    99

    Re: [2008] Progress Bar

    Not really, its just entering a user name, entering a password and clicking on sign in. Perhaps I could use the database search for the progress bar.

  10. #10
    Hyperactive Member cameron2's Avatar
    Join Date
    Mar 2008
    Location
    Australia
    Posts
    401

    Re: [2008] Progress Bar

    Well if thats all your doing then you hardly need a progress bar unless the form u are loading has a video or pictures.
    If you really want a loading bar then you can fake it like in my example but you might want to use a separate thread.

  11. #11

    Thread Starter
    Lively Member Colin Dias's Avatar
    Join Date
    Jan 2008
    Posts
    99

    Re: [2008] Progress Bar

    Well its true I just want to add the progress bar to look "cool". But that code you gave me doesn't work! The progress bar just stays filled at 100% through out.
    Last edited by Colin Dias; Mar 27th, 2008 at 05:18 AM.

  12. #12
    Hyperactive Member cameron2's Avatar
    Join Date
    Mar 2008
    Location
    Australia
    Posts
    401

    Re: [2008] Progress Bar

    ok here is code that will work:
    'add a timer to your form

    Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
    System.Threading.Thread.Sleep(1000)
    ProgressBar1.PerformStep()
    System.Threading.Thread.Sleep(100)
    ProgressBar1.PerformStep()
    System.Threading.Thread.Sleep(100)
    ProgressBar1.PerformStep()
    System.Threading.Thread.Sleep(100)
    ProgressBar1.PerformStep()
    System.Threading.Thread.Sleep(100)
    ProgressBar1.PerformStep()
    System.Threading.Thread.Sleep(100)
    ProgressBar1.PerformStep()
    System.Threading.Thread.Sleep(100)
    ProgressBar1.PerformStep()
    System.Threading.Thread.Sleep(100)
    ProgressBar1.PerformStep()
    System.Threading.Thread.Sleep(100)
    ProgressBar1.PerformStep()
    System.Threading.Thread.Sleep(100)
    ProgressBar1.PerformStep()
    Timer1.Enabled = False
    End Sub
    End Class

    End Sub[/CODE]
    This is a very crude way of doing this and would be much better if you did it through a separate thread search "threading" but you can use it if u want to.

  13. #13

    Thread Starter
    Lively Member Colin Dias's Avatar
    Join Date
    Jan 2008
    Posts
    99

    Re: [2008] Progress Bar

    Now the progress bar is at 0% through out... It doesnt fill up

  14. #14
    Raging swede Atheist's Avatar
    Join Date
    Aug 2005
    Location
    Sweden
    Posts
    8,018

    Re: [2008] Progress Bar

    Why use a timer if you're still going to sleep the UI thread? Set the timers interval to 100 milliseconds and call PerformStep once on each Tick event. Disable the timer when the ProgressBar has reached the Maximum value.

    @Colin Dias,
    Sorry no I dont really know much about KTH, other than that its a good university.
    Rate posts that helped you. I do not reply to PM's with coding questions.
    How to Get Your Questions Answered
    Current project: tunaOS
    Me on.. BitBucket, Google Code, Github (pretty empty)

  15. #15
    Frenzied Member stimbo's Avatar
    Join Date
    Jun 2006
    Location
    UK
    Posts
    1,739

    Re: [2008] Progress Bar

    As a complete cheat if it's purely for visual things rather than actually measuring the likely time to complete you could just set its Style property to Marquee.

    It obviously won't tell them in any way how long the time will take but using the idea of a Thread sleep to do this is completely barmy if you ask me.
    Stim

    Free VB.NET Book Chapter
    Visual Basic 2005 Cookbook Sample Chapter

  16. #16
    Hyperactive Member cameron2's Avatar
    Join Date
    Mar 2008
    Location
    Australia
    Posts
    401

    Re: [2008] Progress Bar

    Yes my bad i dont know why i did wat i did.

  17. #17
    Hyperactive Member cameron2's Avatar
    Join Date
    Mar 2008
    Location
    Australia
    Posts
    401

    Re: [2008] Progress Bar

    @stimbo yeah but he just wants a visual effect

  18. #18
    Frenzied Member stimbo's Avatar
    Join Date
    Jun 2006
    Location
    UK
    Posts
    1,739

    Re: [2008] Progress Bar

    but he just wants a visual effect
    which the Marquee effect will give him without any effort required on his part which seems to suit.

    Colin, incrementing the value by 1 and updating the progress bar is a very simple thing to do. Have you actually tried experimenting yourself or reading the documentation or even performing a basic search on this forum for Progress Bar?

    Rather than simply replying with "I don't know how to do that".
    Stim

    Free VB.NET Book Chapter
    Visual Basic 2005 Cookbook Sample Chapter

  19. #19

    Thread Starter
    Lively Member Colin Dias's Avatar
    Join Date
    Jan 2008
    Posts
    99

    Re: [2008] Progress Bar

    Took stimbo's advice. It looks fine , thanks.

  20. #20
    Lively Member irishlad's Avatar
    Join Date
    Oct 2006
    Location
    Arizona
    Posts
    108

    Re: [2008] Progress Bar

    If its just for aesthetic reasons you can do this:

    Code:
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    
            For i = 1 To 100   'the second number (100) must <= the Maximum property of the progress bar
                ProgressBar1.Value = i
            Next
    
        End Sub

  21. #21
    Raging swede Atheist's Avatar
    Join Date
    Aug 2005
    Location
    Sweden
    Posts
    8,018

    Re: [2008] Progress Bar

    Quote Originally Posted by irishlad
    If its just for aesthetic reasons you can do this:

    Code:
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    
            For i = 1 To 100   'the second number (100) must <= the Maximum property of the progress bar
                ProgressBar1.Value = i
            Next
    
        End Sub
    Actually, that wont work. Take a look at post #5.
    Rate posts that helped you. I do not reply to PM's with coding questions.
    How to Get Your Questions Answered
    Current project: tunaOS
    Me on.. BitBucket, Google Code, Github (pretty empty)

  22. #22

    Thread Starter
    Lively Member Colin Dias's Avatar
    Join Date
    Jan 2008
    Posts
    99

    Re: [2008] Progress Bar

    ....
    Last edited by Colin Dias; Mar 27th, 2008 at 05:19 AM.

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

    Re: [2008] Progress Bar

    Quote Originally Posted by Colin Dias
    How do you change the profile name?
    What profile are you talking about?
    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

  24. #24

    Thread Starter
    Lively Member Colin Dias's Avatar
    Join Date
    Jan 2008
    Posts
    99

    Re: [2008] Progress Bar

    ....
    Last edited by Colin Dias; Mar 27th, 2008 at 05:18 AM.

  25. #25

    Thread Starter
    Lively Member Colin Dias's Avatar
    Join Date
    Jan 2008
    Posts
    99

    Re: [2008] Progress Bar

    Quote Originally Posted by irishlad
    If its just for aesthetic reasons you can do this:

    Code:
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    
            For i = 1 To 100   
                ProgressBar1.Value = i
            Next
    
        End Sub
    Actually this worked the best. I used it in the button click event. I used a delay in the loop to make it look better.
    Code:
    For i = 1 To 100   'the second number (100) must <= the Maximum property of the progress bar
                ProgressBar1.Value = i
                System.Threading.Thread.Sleep(25)
            Next
    Last edited by Colin Dias; Mar 27th, 2008 at 03:35 AM.

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

    Re: [2008] Progress Bar

    What has your VBForums profile got to do with ProgressBars or VB.NET? Please keep each thread to one topic and one relevant topic.

    I also have to say that making your application load more slowly by sleeping the UI thread for 2.5 seconds so that you can show a ProgressBar that "looks cool" is really not a good idea. I would sooner have the app load faster. I think I speak for pretty much all users in saying that.
    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

  27. #27
    Hyperactive Member cameron2's Avatar
    Join Date
    Mar 2008
    Location
    Australia
    Posts
    401

    Re: [2008] Progress Bar

    Jmc you might find that more vb beginners (like me) prefer their application to look 'cool' with visual effects i know i have done a fake loading bar just for an effect.

  28. #28
    Member
    Join Date
    Sep 2006
    Posts
    53

    Re: [2008] Progress Bar

    ok propably you r newbie like me and you dont understand the steps from pro's... i try to help you step by step

    i did it like this : and works grate

    first you need 2 forms :

    1) frmstart.vb
    2) LoginForm.vb

    first you need the code to show login form

    Code:
        Private Sub frmStart_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            LoginForm.MdiParent = Me
            LoginForm.Show()
        End Sub

    in your LoginForm.vb you need

    1) UsernameTextBox + label if you want
    2) PasswordTextBox + label if you want
    3) ProgressBar1
    4) Timer1
    5) label1

    after that you place the code in the form for the timer

    Code:
        Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
            ProgressBar1.Value += 2
    
            If ProgressBar1.Value <= 30 Then
                Label1.Text = "Initialized Application ....."
    
            ElseIf ProgressBar1.Value <= 50 Then
                Label1.Text = "Loading Data Component ....."
    
            ElseIf ProgressBar1.Value <= 70 Then
                Label1.Text = "Integration Database ...."
    
            ElseIf ProgressBar1.Value <= 100 Then
                Label1.Text = "Please Wait ...."
    
            End If
    
            If ProgressBar1.Value = 100 Then
                Timer1.Enabled = False
                'ηταν στη θεση (3)
                Me.Hide()
                frmStart.ToolStripStatusLabel1.Text = UsernameTextBox.Text
                frmStart.ToolStripStatusLabel2.Text = "Χρήστης :"
                frmStart.MenuStrip1.Enabled = True
            End If
    
    
        End Sub
    and finaly you call timer from button enter
    *NOTE* you call the timer after the sucside login

    Code:
       Private Sub OK_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OK.Click
            Dim sql = "SELECT name ,code FROM SC WHERE name='" & UsernameTextBox.Text & "' AND code='" & PasswordTextBox.Text & "'"
    
            cmd = New OleDbCommand(sql, conn)
            conn.Open()
            Dim dr As OleDbDataReader = cmd.ExecuteReader
    
            Try
                If dr.Read = False Then
                    MessageBox.Show("Λάθος Χρήστης ή Κωδικός. Παρακαλώ προσπαθήστε πάλι...")
                Else
                    'θεση (3)
                    Timer1.Start()
    
                End If
            Catch ex As Exception
                MsgBox(ex.Message)
            End Try
    
            conn.Close()
    
    
    
        End Sub

  29. #29
    Member
    Join Date
    Sep 2006
    Posts
    53

    Re: [2008] Progress Bar

    Last edited by Chrisad; Mar 28th, 2008 at 07:49 AM.

  30. #30
    Member
    Join Date
    Sep 2006
    Posts
    53

    Re: [2008] Progress Bar

    Last edited by Chrisad; Mar 28th, 2008 at 07:49 AM.

  31. #31
    Member
    Join Date
    Sep 2006
    Posts
    53

    Re: [2008] Progress Bar





    Last edited by Chrisad; Mar 28th, 2008 at 07:50 AM.

  32. #32
    Raging swede Atheist's Avatar
    Join Date
    Aug 2005
    Location
    Sweden
    Posts
    8,018

    Re: [2008] Progress Bar

    Whats with all the empty posts Chrisad?
    Rate posts that helped you. I do not reply to PM's with coding questions.
    How to Get Your Questions Answered
    Current project: tunaOS
    Me on.. BitBucket, Google Code, Github (pretty empty)

  33. #33
    Frenzied Member MaximilianMayrhofer's Avatar
    Join Date
    Aug 2007
    Location
    IM IN YR LOOP
    Posts
    2,001

    Re: [2008] Progress Bar

    I don't want to offend, but it's completely and unforgiveably idiotic to slow down a program just so your program 'looks' like it's doing something. The best way to make a user happy is to minimise the amount of time they have to spend waiting on your application to do something.

    A progress bar is only useful when you perform large routines or calculations. This is so that the user knows that something is actually happening and that the computer hasn't frozen up.

    So if you're looking for 'coolness', then find other ways of doing it. And for goodness sake don't use the sleep command on a thread. Usage like the type above make me think it should be banned.

    @Atheist: They aren't empty, just full of a bunch of screenshots that show every step in his progress bar.
    Last edited by MaximilianMayrhofer; Mar 28th, 2008 at 07:59 AM.

  34. #34
    Frenzied Member MaximilianMayrhofer's Avatar
    Join Date
    Aug 2007
    Location
    IM IN YR LOOP
    Posts
    2,001

    Re: [2008] Progress Bar

    vb.net Code:
    1. Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
    2.         ProgressBar1.Value += 2
    3.  
    4.         If ProgressBar1.Value <= 30 Then
    5.             Label1.Text = "Initialized Application ....."
    6.  
    7.         ElseIf ProgressBar1.Value <= 50 Then
    8.             Label1.Text = "Loading Data Component ....."
    9.  
    10.         ElseIf ProgressBar1.Value <= 70 Then
    11.             Label1.Text = "Integration Database ...."
    12.  
    13.         ElseIf ProgressBar1.Value <= 100 Then
    14.             Label1.Text = "Please Wait ...."
    15.  
    16.         End If
    17.  
    18.         If ProgressBar1.Value = 100 Then
    19.             Timer1.Enabled = False
    20.             'ηταν στη θεση (3)
    21.             Me.Hide()
    22.             frmStart.ToolStripStatusLabel1.Text = UsernameTextBox.Text
    23.             frmStart.ToolStripStatusLabel2.Text = "Χρήστης :"
    24.             frmStart.MenuStrip1.Enabled = True
    25.         End If
    26.  
    27.  
    28.     End Sub

    Why are you using Me.Hide()? It's an unnecessary waste of system resources. Once the logon is successful, the logon form should be disposed of. As best practice, users should be validated even before the main application loads.

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

    Re: [2008] Progress Bar

    This thread is all about what's considered "cool" and not what's good. If you want to be a real software developer then you had best realise that writing good code is what's cool. The rest is just window dressing that is worse than pointless because it makes your app run slower. If that's what you want then logic has no place here.
    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

  36. #36

    Thread Starter
    Lively Member Colin Dias's Avatar
    Join Date
    Jan 2008
    Posts
    99

    Re: [2008] Progress Bar

    The application was taking a while to load up so I wanted to add a progress bar to show the user that the program was not freezing up.

    Alternatively I thought of using an hour glass for the pointer.
    Code:
    Button1.Cursor = Cursors.WaitCursor
    Used in the login button's click event.
    Last edited by Colin Dias; Mar 29th, 2008 at 12:48 AM.

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

    Re: [2008] Progress Bar

    Quote Originally Posted by Colin Dias
    The application was taking a while to load up so I wanted to add a progress bar to show the user that the program was not freezing up.

    Alternatively I thought of using an hour glass for the pointer.
    Code:
    Button1.Cursor = Cursors.WaitCursor
    Used in the login button's click event.
    If you want an indicator of activity, rather than actual progress, then just set the Style property to Marquee and do nothing else.
    Last edited by jmcilhinney; Mar 29th, 2008 at 01:54 AM.
    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

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