devxlogo

Handling Erros In The Form_Load Routine

Handling Erros In The Form_Load Routine

In VB3, the PostMessage API can cancel an error during Form_Load. Theform unloads if you send a WM_CLOSE message to the loaded window in theerror handler of the Form_Load routine. It is not easy to find out fromthe calling routine exactly why the form unloaded. In VB4, you can create a property on your form to indicate success orfailure, and unload the form from the calling procedure depending uponthe value of that property:

 Public SuccessfulLoad As Boolean ' creates the property Form1.SuccessfulLoadPrivate Sub Form_Load()	SuccessfulLoad = True	If An Error Occurs Then	SuccessfulLoad = False	End IfEnd Sub

In the calling procedure:

 Sub LoadTheFubarForm()	Dim MyForm As Form1	Set MyForm = New Form1	Load MyForm	If MyForm.SuccessfulLoad Then		MyForm.Show vbModal	End If	Unload MyForm	Set MyForm = NothingEnd Sub
See also  5 Tips for Working With an Onsite Interpreter
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