Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

VB form blank during heavy process

Posted on 2004-10-27
4
Medium Priority
?
238 Views
Last Modified: 2012-05-05
I have an application processessing upwards of 80000 records.
I have a progress bar to track progress of records
screen does not refresh with new progress information while in processing loop
i.e. no 10%, 15%, ...

any suggestions on how to get the progress bar (and rest of form) to display during this process time?

note question is urgent
0
Comment
Question by:gwosgood
[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
  • 2
4 Comments
 
LVL 2

Author Comment

by:gwosgood
ID: 12427447
note:    form.refresh does not work
0
 
LVL 12

Accepted Solution

by:
fulscher earned 2000 total points
ID: 12427488
Yes - add a DoEvents command in the most inner loop. DoEvents gives the OS the chance to process other events which have queued up - this includes repainting the UI.

You'll probably notice that DoEvents is quite expensive in terms of run-time of your program. Therefore, I'd suggest to do a DoEvents only every tenth (or so) time:

Dim DECnt as Long  'DoEvent counter
Const DETrigger = 10
...

if DECnt = 0 Then DoEvents
DECnt = DECnt + 1
If DECnt >= DETrigger Then DECnt = 0


HTH, J
0
 
LVL 2

Author Comment

by:gwosgood
ID: 12427559
fulscher,

very well done
very simple and complete solution, much appreciated
0
 
LVL 32

Expert Comment

by:Erick37
ID: 12427657
Note that DoEvents will allow the user to interact with the form while your loop is running.  You should therefore take care when using DoEvents to prevent undesired events from triggering while your loop is running.  This may include disabling the command button which runs the loop.

e.g.

Sub Command1_Click()

    Command1.enabled = false ' Disable to prevent reentrance
    bProcessing = True ' flag that the loop is running

    Do While ( ... )
        'Process Records
        DoEvents
    Loop

    bProcessing = false
    Command1.enabled = true ' Reenable after complete

End Sub

Also take care that you do not unexpectedly exit the program in the middle of the loop

Sub Form_QueryUnload(...)

    'Check the state of the processing...
    If bProcessing Then
         'The loop is running ...

If you do not want to use DoEvents, then you may try:

Progress1.Value = x
Progress1.Refresh 'Redraw the progressbar

Hope it helps!

0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say 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

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
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…
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 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…
Suggested Courses

604 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