Solved

Implementing a progressbar in VB.NET

Posted on 2004-04-24
8
534 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
  • 2
8 Comments
 
LVL 48

Expert Comment

by:AlexFM
ID: 10910550
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
ID: 10911351
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
ID: 10911368
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
Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

 
LVL 9

Expert Comment

by:p_sie
ID: 10913008
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
ID: 10914106
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
ID: 10915946
Doesn't look to me you can implement a loop.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

This tutorial demonstrates one way to create an application that runs without any Forms but still has a GUI presence via an Icon in the System Tray. The magic lies in Inheriting from the ApplicationContext Class and passing that to Application.Ru…
Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

739 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