Private Sub AddToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles AddToolStripMenuItem.Click

    Dim numbers() As Integer = {myarray(x)}
    Dim element As Integer
    Dim total As Integer

    For Each element In numbers
        total = total + element
    Next element

End Sub

This is the code I have for adding the numbers in an array, but I keep getting an error that pertains to the top line that says "Handles clause requires a WithEvents variable defined in the containing type or one of it's base types". The words "AddToolStripMenuItem" are underlined. How can I fix this?
This is an assignment for school and I really need help!

Your sub (code in that sub) is looking for an object -

ByVal sender As System.Object

When you declare an object, you have to show it. In this event you are coding under click event, refering to an object, probably a menu? (AddToolStripMenuItem)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.