Solved

List box or Label info show immediately

Posted on 2000-03-25
8
167 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
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
Industry Leaders: 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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone 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

Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
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…

749 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