Solved

List box or Label info show immediately

Posted on 2000-03-25
8
172 Views
Last Modified: 2010-05-18
I have a Label and a List Box.  I have a command.click sub that has a loop sending mail.  In the loop, with each iteration, I change the text in the label and list box to keep track of the progress.  The problem is that it only displays after the loop has finished.  I also have a label that says "Starting" but it doesn't display either until the whole sub is finished.

How can I make them change their displays immediately in the loop?
0
Comment
Question by:donb1
[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
8 Comments
 
LVL 2

Expert Comment

by:ggilman
ID: 2656701
Put a DOEvents in the middle of the loop. This will allow the contents to be updated.
0
 
LVL 1

Expert Comment

by:PatrickVD
ID: 2656706
Hi donb,

Try to add a DoEvents statement just after the update of the Label Caption property, this will probably fix your problem.

Label1.Caption = "Starting..."
DoEvents
Do While Condition= True
   Label2.Caption = "Item Name"
   List1.AddItem "Item Data"
   DoEvents
   'Do your process intensive work now
Loop

The problem is that due to the processing loop, you are not giving away enough time to the window handler to update your user interface.

Try it, I'm sure it will solve your problem !

Patrick.
0
 

Expert Comment

by:dmridg
ID: 2656836
If you insert the "Repaint" method after each label change it will force the repaint of the screen.

For example

Label1.Caption = "New Value"
Me.Repaint
0
Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

 
LVL 14

Accepted Solution

by:
mcrider earned 50 total points
ID: 2656842
donb1,

You will find that if you place a "DoEvents" in your loop, your program will update the listbox and the label, HOWEVER, you will also find that you will be able to click the button that started the loop more than once and your loop will be kicked of each time you click it... while the first iteration of the loop is running. This will DEFINATELY cause problems with what you are doing in the loop.

You can solve this problem two ways...

1) If you are going to perform a "DoEvents", then do it like this:

Command1.Enabled = False
Label1.Caption = "Starting..."
DoEvents
Do While Condition= True
   Label2.Caption = "Item Name"
   List1.AddItem "Item Data"
   DoEvents
   'Do your process intensive work now
Loop
Command1.Enabled = True

Also remember that you will be able to click other buttons and menus while the loop is running... If this will interfere with the loop running, then you may actually want to do this instead:


Form1.Enabled = False
Label1.Caption = "Starting..."
DoEvents
Do While Condition= True
   Label2.Caption = "Item Name"
   List1.AddItem "Item Data"
   DoEvents
   'Do your process intensive work now
Loop
Form1.Enabled = True


HOWEVER... There is another way to get your label and listbox to update without using "DoEvents"...

Inside your loop, explicitly call a refresh of the label and list.  For example:

Do While Condition= True
   Label2.Caption = "Item Name"
   Label2.Refresh
   List1.AddItem "Item Data"
   List1.Refresh
   'Do your process intensive work now
Loop


Cheers!®©
0
 
LVL 14

Expert Comment

by:mcrider
ID: 2656846
dmridg, REPAINT is not a valid statement...
0
 

Author Comment

by:donb1
ID: 2656952
Repaint doesn't work

mcrider had the best answer and should get the points.  DOEvents is the easy answer and works except for the problems mcrider pointed out.

Thanks to the others for their comments too.
0
 

Author Comment

by:donb1
ID: 2656953
Thanks
0
 
LVL 14

Expert Comment

by:mcrider
ID: 2657646
Thanks for the points! Glad I could help!


Cheers!®©
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Suggested Courses
Course of the Month9 days, 19 hours left to enroll

623 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