VB Migration Partner

KNOWLEDGE BASE - Forms and controls


Previous | Index | Next 

[INFO] DoEvents6 calls can cause weird user interface behaviors

VB6 apps may invoke the DoEvents methods to accomplish a variety of tasks, the most important of which are

  1. allowing the Windows message pump process incoming keyboard and mouse messages, for example to let the Click event of a button fire when the user clicks on the button while the application is performing a CPU-intensive task
  2. refreshing the user interface and ensure that controls display their correct value even if the application is running a tight loop or is otherwise busy

It should be noted that using DoEvents just for updating the user interface (case B) isn’t a good idea both under VB6 or .NET. In fact, in this case it’s preferable to use the Refresh method of the form or, even better, of the individual control that must be updated.

The Microsoft Upgrade Wizard and other similr tools convert the VB6 DoEvents methods into the .NET Application.DoEvents method, on the assumption that the two methods are roughly equivalent. However, the Application.DoEvents method is a Sub, whereas original VB6 DoEvents method is a function that returns the number of loaded forms.

To account for this minor difference, VB Migration Partner maps DoEvents to the DoEvents6 helper method, which behaves like the VB6 method it is meant to replace.

Occasionally, a few users have reported a few minor problems to the user interface – for examples, controls that update incorrectly or that appear to be disabled – and that these problems go away by removing one or more calls to the DoEvents6 helper method.

It is important to emphasize that, in such cases, the responsible for this misbehavior is the Application.DoEvents method, not our DoEvents6 helper method. In fact, DoEvents6 is nothing but a very thin wrapper for the actual .NET method, as it is apparent by looking at DoEvents6 definition in VB Migration Partner’s support library:

        Public Function DoEvents6() As Integer
            Application.DoEvents()
            ' in case it is being invoked from a thread that hasn't initialized Forms6
            If Forms6 IsNot Nothing Then Return Forms6.Count
            ' return 0 if no open forms
            Return 0
        End Function

When you notice that the user interface doesn’t look as expected, you can easily prove that our DoEvents6 method isn’t responsible for the problem by replacing all its occurrences with calls to Application.DoEvents. You will see that the problem persists.

Unfortunately, this problem isn’t strictly related to migration and to VB Migration Partner, and no generic solution is available.

Our tech support can’t help in these cases. We can only suggest that you replace DoEvents6 with a plain Refresh and see what happens. If this fix can’t be used – because you need to trap keyboard or mouse actions – or doesn’t solve the problem, you may try deleting the DoEvents6 call completely. If this latter approach doesn’t work, you will have to carefully examine the entire execution flow and try to understand what can cause the problem in question.

Previous | Index | Next 




Follow Francesco Balena on VB6 migration’s group on

LinkedIn





Read Microsoft Corp’s official case study of a VB6 conversion using VB Migration Partner.




Code Architects and its partners offers remote and onsite migration services.

More details




Subscribe to our free newsletter for useful VB6 migration tips and techniques.

newsletter



To learn more about your VB6 applications, run VB6 Analyzer on your source code and send us the generated text file. You will receive a detailed report about your VB6 applications and how VB Migration Partner can help you to quickly and effectively migrate it to .NET.

Get free advice



A fully-working, time-limited Trial Edition of VB Migration Partner allows you to test it against your actual code

Get the Trial




The price of VB Migration Partner depends on the size of the VB6 application, the type of license, and other factors

Request a quote




Migrating a VB6 application in 10 easy steps

Comparing VB Migration Partner with Upgrade Wizard

Migration tools: Feature Comparison Table

All whitepapers