[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 282
  • Last Modified:

How to work with status bar in my vb.net programme.

I got an application and it takes at least 10 to 15 minutes to run and I want to know the status of where it is
running. I tried several examples but it shows the status bar but the status bar never moves to anywhere. After
each procedure in my programme I want to show the text and the status bar moved. how to do that. I'm tired of seeing
the examples though.

Thanks
vm
0
vmandem
Asked:
vmandem
  • 2
1 Solution
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
Do you mean a ProgressBar (a status bar typically doesn't move...).

Without seeing your code or knowing what your app does we can only give you simple examples:

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Button1.Enabled = False
        ProgressBar1.Value = 0

        sub1()
        ProgressBar1.Value = (1 / 3) * ProgressBar1.Maximum
        ProgressBar1.Refresh()
        Application.DoEvents()

        sub2()
        ProgressBar1.Value = (2 / 3) * ProgressBar1.Maximum
        ProgressBar1.Refresh()
        Application.DoEvents()

        sub3()
        ProgressBar1.Value = (3 / 3) * ProgressBar1.Maximum
        ProgressBar1.Refresh()
        Application.DoEvents()

        MsgBox("Done")

        Button1.Enabled = True
    End Sub

    Private Sub sub1()
        System.Threading.Thread.Sleep(5000) ' five seconds
    End Sub

    Private Sub sub2()
        System.Threading.Thread.Sleep(3000) ' three seconds
    End Sub

    Private Sub sub3()
        System.Threading.Thread.Sleep(7000) ' seven seconds
    End Sub
0
 
vmandemAuthor Commented:
Idle Mind

I have a form and I created the progress bar and all my procedures are in a class.
Once I click the button on the form it goes to the class and runs the procedures.
I want to set the progress bar moving after each procedure and I want to put the
text after next to the progress bar showing where I'm.

I ran your example but the progress bar does not move. what is
Private Sub sub1()
        System.Threading.Thread.Sleep(5000) ' five seconds
    End Sub

Where to create them.

vm
0
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
Here is an example of an event being raised by a class to update the progress:

Public Class Form1
    Inherits System.Windows.Forms.Form

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Button1.Enabled = False

        ProgressBar1.Value = 0
        Label1.Text = ""
        Application.DoEvents()

        Dim t As New Test
        AddHandler t.progress, AddressOf Me.t_progress
        t.doWork()

        MsgBox("Done")

        Button1.Enabled = True
    End Sub

    Private Sub t_progress(ByVal val As Integer, ByVal max As Integer, ByVal msg As String)
        ProgressBar1.Value = val / max * ProgressBar1.Maximum
        ProgressBar1.Refresh()
        Label1.Text = msg
        Label1.Refresh()
        Application.DoEvents()
    End Sub

End Class

Public Class Test

    Public Event progress(ByVal val As Integer, ByVal max As Integer, ByVal msg As String)

    Public Sub doWork()
        sub1()
        sub2()
        sub3()
    End Sub

    Private Sub sub1()
        System.Threading.Thread.Sleep(3000) ' this is just to simulate some work being done!
        RaiseEvent progress(1, 3, "sub1() complete")
    End Sub

    Private Sub sub2()
        System.Threading.Thread.Sleep(1000) ' this is just to simulate some work being done!
        RaiseEvent progress(2, 3, "sub2() complete")
    End Sub

    Private Sub sub3()
        System.Threading.Thread.Sleep(2000) ' this is just to simulate some work being done!
        RaiseEvent progress(3, 3, "sub3() complete")
    End Sub

End Class
0
 
Bob LearnedCommented:
Also, if there is some tight code being run, you might want to use Application.DoEvents to allow the progress bar to update.

Bob
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now