?
Solved

Confused about paint, refresh, focus for form...

Posted on 2004-11-30
5
Medium Priority
?
147 Views
Last Modified: 2010-08-05
I have a VB program that reads some large text files and processes the data in them; it can take several minutes to run. Form "frmProgress" contains the guts of the code, and is displayed while the processing is going on. (The processing code is executed from its load event.) It has some informative information displayed (using label controls), and it also has a progress bar that is updated while the code runs. My problem is this: if I open another app and its window covers my "Progress..." form, when I try to go back to my "Progress... " form, the only thing on it is the progress bar ... presumably because this bar gets refreshed every time I read & process a line from a file. Why doesn't all the other stuff "repaint"? If I do a form refresh at the same time that I do the progress bar refresh, the form looks too jumpy ... isn't there something that is supposed to automatically repaint my window when its covered/uncovered? Or has focus and then loses focus? This must be a really simple thing, but I just can't figure it out ... even after paging through multiple manuals that I have. I guess I just don't know what I'm supposed to be looking for! Help!
0
Comment
Question by:alicia1234
  • 3
  • 2
5 Comments
 
LVL 32

Accepted Solution

by:
Erick37 earned 600 total points
ID: 12711040
Place a DoEvents statement in the loop so that your form can repaint.

Do While....

    'Some more code...
    DoEvents

Loop
0
 

Author Comment

by:alicia1234
ID: 12711098
How often should I "DoEvents" ? Does it cause the program to run more slowly?
0
 

Author Comment

by:alicia1234
ID: 12711334
OK ... that seemed to do the trick. And doesn't seem to slow down my program. Thanks.
0
 
LVL 32

Expert Comment

by:Erick37
ID: 12711357
Just once in the loop, and it will not affect performance too much because it will not do anything unless there is an event to process.

Be aware however, that while your loop is running DoEvents will allow events such as Command button click events to run.  Be sure to disable any buttons or other controls whose events you do not want to run while the loop is running.

e.g.

Command1.Enabled = False
Do While....

    'Some more code...    
    'Update Progressbar
    DoEvents

Loop
Command1.Enabled = True
0
 

Author Comment

by:alicia1234
ID: 12711510
There aren't any buttons on the form, so I'm covered. Thanks.
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
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

850 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