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

devx-admin

Share the Post: