Solved

List box or Label info show immediately

Posted on 2000-03-25
8
164 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
Comment Utility
Put a DOEvents in the middle of the loop. This will allow the contents to be updated.
0
 
LVL 1

Expert Comment

by:PatrickVD
Comment Utility
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
Comment Utility
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
 
LVL 14

Accepted Solution

by:
mcrider earned 50 total points
Comment Utility
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
What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

 
LVL 14

Expert Comment

by:mcrider
Comment Utility
dmridg, REPAINT is not a valid statement...
0
 

Author Comment

by:donb1
Comment Utility
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
Comment Utility
Thanks
0
 
LVL 14

Expert Comment

by:mcrider
Comment Utility
Thanks for the points! Glad I could help!


Cheers!®©
0

Featured Post

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Suggested Solutions

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
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 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…

728 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

13 Experts available now in Live!

Get 1:1 Help Now