Browse DevX
Sign up for e-mail newsletters from DevX

Tip of the Day
Language: Visual Basic
Expertise: Beginner
Sep 30, 1999



Building the Right Environment to Support AI, Machine Learning and Deep Learning

Ask the Form Itself Whether it's Loaded

Occasionally you initialize a form but don't load it. You might do this to read in initial application Registry values. After that, any references to control properties on the form automatically cause your Form_Load event to fire, whether or not you intended to fire the Form_Load event. If you want to know programmatically whether your form has been loaded, implement these steps.
Add a private Boolean variable to your form and call it m_bLoaded:
Option Explicit

Dim m_bLoaded as Boolean
Add Property Let and Get procedures to provide public read and write access to your form's internal m_bLoaded variable:
Public Property Get Loaded() As Boolean
	Loaded = m_bLoaded
End Property
Public Property Get Let(ByVal bLoaded As Boolean)
	m_bLoaded = bLoaded
End Property
Add this line of code to your form's Load event:
Me.Loaded = True
To see whether your form is loaded from other modules or other forms, use this code:
If  FormName.Loaded = True Then
	' Do stuff that can only be done if the form 
	' has been loaded (i.e., set control properties)
Using this code helps prevent you from accidentally firing the Form_Load event.
Scott McFadden
Comment and Contribute






(Maximum characters: 1200). You have 1200 characters left.



Thanks for your registration, follow us on our social networks to keep up-to-date