devxlogo

Use Refresh, Not DoEvents

Use Refresh, Not DoEvents

When executing code and tying up the system, developers often use a label or status bar to display messages. If you simply assign your text or message to the control (for example, lblMsg.Caption = “Still working…”), you won’t see the text because your code loop isn’t allowing the form to respond to the message. To make the message visible, use the Refresh method of the control. Don’t use the DoEvents command to refresh the text to the user-this introduces re-entrancy issues. Note that displaying messages slows down performance, so use them intelligently:

 Private Sub Command1_Click()	Dim J As Long	For J = 1 To 1000		Label1.Caption = "Message " & J		Label1.Refresh	Next JEnd Sub
devxblackblue

About Our Editorial Process

At DevX, we’re dedicated to tech entrepreneurship. Our team closely follows industry shifts, new products, AI breakthroughs, technology trends, and funding announcements. Articles undergo thorough editing to ensure accuracy and clarity, reflecting DevX’s style and supporting entrepreneurs in the tech sphere.

See our full editorial policy.

About Our Journalist