Solved

List box or Label info show immediately

Posted on 2000-03-25
8
170 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
Independent Software Vendors: 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!

 
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

Enroll in May's Course of the Month

May’s Course of the Month is now available! Experts Exchange’s Premium Members and Team Accounts have access to a complimentary course each month as part of their membership—an extra way to increase training and boost professional development.

Question has a verified solution.

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

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.
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…

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