• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 239
  • Last Modified:

VB form blank during heavy process

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
gwosgood
Asked:
gwosgood
  • 2
1 Solution
 
gwosgoodIT MgrAuthor Commented:
note:    form.refresh does not work
0
 
fulscherCommented:
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
 
gwosgoodIT MgrAuthor Commented:
fulscher,

very well done
very simple and complete solution, much appreciated
0
 
Erick37Commented:
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

Take Control of Web Hosting For Your Clients

As a web developer or IT admin, successfully managing multiple client accounts can be challenging. In this webinar we will look at the tools provided by Media Temple and Plesk to make managing your clients’ hosting easier.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now