Solved

Implementing a progressbar in VB.NET

Posted on 2004-04-24
8
527 Views
Last Modified: 2012-05-04
I want to implement a progressbar to show the mail merge progress after a user has selected a letter from a combobox on Form1.  My script so far as follows:

Private Sub cmdOK_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdOK.Click
        If ComboBox1.SelectedItem = "Letter1" Then
            Module1.Letter1()
        ElseIf ComboBox1.SelectedItem = "Letter2" Then
            Module1.Letter2()
        End If

*Module1 contains the mail merge script
I want the progress bar to move on Form1 while the mail merge (Module1) is executing.  I would appreciate any solutions as this is my first VB.net project.
0
Comment
Question by:symanski
  • 2
  • 2
  • 2
8 Comments
 
LVL 48

Expert Comment

by:AlexFM
Comment Utility
Pass progressbar reference to Letter function:

Module1.Letter1(progressBar1)

In the function:

Sub Letter1(progressBar as ProgressBar)

    Do While ...
        ' do something

        progressBar.Value = ...   ' set progress bar position
        Application.DoEvents()    ' update window
    End

End Sub
0
 

Author Comment

by:symanski
Comment Utility
I'm still having problems with the 'Do While' statement in the letters function.  Would I need to use a loop to update the progressbar until the mail merge was completed.

Any suggestions would be appreciated.

Thanks  
0
 
LVL 48

Accepted Solution

by:
AlexFM earned 125 total points
Comment Utility
If you don't have any loop inside of Letter1 function, this is impossible. This solution works if you already have some loop, and you can update progressbar from it.
0
Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 9

Expert Comment

by:p_sie
Comment Utility
If you don't have a loop and you want to display something that will make the user understand that the computer
is working, display some kind of form with a timer on it, that will change an icon every 1 second...
Like the compying progress window of windows (2 folders with files moving between, and some wrong calculation of the
time remaining...)
0
 

Author Comment

by:symanski
Comment Utility
Is there any way of implementing a loop into the existing module below:
   
Sub Letter1(ByVal progressBar As ProgressBar)
        Dim wapp As Word.Application
        wapp = CreateObject("Word.Application")
        wapp.Documents.Open("path...")
        wapp.Visible = True
        With wapp.ActiveDocument.Mailmerge
        .Destination = Word.WdMailMergeDestination.wdSendToNewDocument
With  .Datasource
         .firstrecord = Word.WdMailMergeDefaultRecord.wdDefaultFirstRecord
         .lastrecord = Word.WdMailMergeDefaultRecord.wdDefaultLastRecord
End With
        .execute(pause:=False)
End With
        wapp.Windows.Item("Letter1.doc").Close()
0
 
LVL 9

Assisted Solution

by:p_sie
p_sie earned 125 total points
Comment Utility
Doesn't look to me you can implement a loop.
0

Featured Post

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

If you're writing a .NET application to connect to an Access .mdb database and use pre-existing queries that require parameters, you've come to the right place! Let's say the pre-existing query(qryCust) in Access takes a Date as a parameter and l…
Introduction When many people think of the WebBrowser (http://msdn.microsoft.com/en-us/library/2te2y1x6%28v=VS.85%29.aspx) control, they immediately think of a control which allows the viewing and navigation of web pages. While this is true, it's a…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

763 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

Need Help in Real-Time?

Connect with top rated Experts

6 Experts available now in Live!

Get 1:1 Help Now