Blueblade11
Blueblade11

Reputation: 11

events not loading in visual basic on initial form load

I'm not very good at explaining myself, but I have a problem where on starting debug in visual basic, my events for the form load arent loading.

Private Sub frmMain_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    Application.SetUnhandledExceptionMode(UnhandledExceptionMode.CatchException)
    boolUserLog = False  'global variables
    fButtonsEnable() 'function call for enable buttons
    fFormLocation() 'function call for fixing form location
    Debug.WriteLine("|--START--|")
    Debug.WriteLine("COMPLETE LOAD")
    Debug.WriteLine("|---END---|")
    txtSearch.Text = strSearchText
End Sub

I've tried searching and am totally lost. The form itself loads fine, and other events in MyBase.Load in other forms work, but when this ^ particular form loads the debug lines don't show up in the output, which means none of this is loaded, I guess.

Any help?

Upvotes: 1

Views: 1000

Answers (1)

Hans Passant
Hans Passant

Reputation: 941317

   Application.SetUnhandledExceptionMode(UnhandledExceptionMode.CatchException)

You cannot change the exception handling mode after controls were created. This statement will always throw an InvalidOperationException. So your Debug.WriteLine() statements will never execute.

What goes wrong next is a very, very, cr*ppy problem on the 64-bit version of Vista or Windows 7. You don't actually see that exception, the debugger doesn't tell you about it. So you have no idea what's going wrong, code just doesn't seem to execute. This problem, and its workarounds, are described in detail in this answer.

The solution is the one that's covered in the 4th bullet of that answer. This code does not belong in your Load event handler. In VB.NET, use the Application.Startup event. Project + Properties, Application Tab, scroll down, click the "View Application Events" button and add an event handler for the Startup event.

Upvotes: 1

Related Questions