Solved

VB form blank during heavy process

Posted on 2004-10-27
237 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
Question by:gwosgood
    4 Comments
     
    LVL 2

    Author Comment

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

    Accepted Solution

    by:
    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
    fulscher,

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

    Expert Comment

    by:Erick37
    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

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Prepare to Pass the CompTIA A+ 900 Series Exam

    CompTIA aims to adapt its A+ Certification to reflect the most current knowledge and skills needed by today's IT professionals--and this year's 2016 exam is harder than ever. This certification is one of the most highly-respected and sought after in IT.

    Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
    Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
    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…

    884 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

    18 Experts available now in Live!

    Get 1:1 Help Now