none
An error I don't understand?

    Question

  • So, I have made a performance optimization program and I have an error that I don't understand. Here's my code:

        Private Sub Form1_Load(sender As Object, e As EventArgs) Handles Form1.Load
            Dim mmc() As Process = Process.GetProcessesByName("mmc.exe")
            For Each Process As Process In mmc
                Process.Kill()
                Me.Show()
            Next
        End Sub
    End Class

    On the first line, where it says 'Form1.Load', it recons there's an error:

    Handles clause requires a WithEvents variable defined in the containing type or one of its base types.

    I really want this fixed! I am totally confused now and I would like someone to fix this up!

    Monday, April 24, 2017 7:59 AM

Answers

  • That's the wrong signature handles clause for the form's .Load event.

    It should be:

    Private Sub _
            Form1_Load(sender As System.Object, _
                       e As System.EventArgs) _
                       Handles MyBase.Load
    
    ' Code here
    
    End Sub


    "A problem well stated is a problem half solved.” - Charles F. Kettering


    Monday, April 24, 2017 9:48 PM

All replies

  • That's the wrong signature handles clause for the form's .Load event.

    It should be:

    Private Sub _
            Form1_Load(sender As System.Object, _
                       e As System.EventArgs) _
                       Handles MyBase.Load
    
    ' Code here
    
    End Sub


    "A problem well stated is a problem half solved.” - Charles F. Kettering


    Monday, April 24, 2017 9:48 PM
  • Wait, lol am I dumb? I could've put it in Form1! Thanks for the response anyway!
    Tuesday, April 25, 2017 12:00 AM
  • Wait, lol am I dumb? I could've put it in Form1! Thanks for the response anyway!

    If you double click on any form, the IDE will fill in an empty sub with that Handles clause.

    I made a blank project, and added a form2, double clicking on each gives this:

        Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
        
    End Sub Private Sub Form2_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
    End Sub

    Wednesday, April 26, 2017 2:35 AM
  • HI VBProgrammer456,

    It seems that Frank L's post solved your issue, please remember to close your thread by marking his post as answer, it is beneficial to the other communities who face the same issue.

    Thanks for your understanding.

    Nest Regards,

    Cherry Bu


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Wednesday, April 26, 2017 3:24 AM
    Moderator