I got a button array of 40 buttons
And i handle all the button events in 1 sub .
But i need to know what button is pressed.
Can someone help me ?

Private bttonArray(41) As Button
    Public Sub Hoofdscherm_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

        REM place the Buttons in a  array 
        bttonArray(1) = Button1
        bttonArray(2) = Button2
        bttonArray(3) = Button3
        bttonArray(4) = Button4
        bttonArray(5) = Button5
        bttonArray(6) = Button6
        bttonArray(7) = Button7
        bttonArray(8) = Button8
        bttonArray(9) = Button9
        bttonArray(10) = Button10
        bttonArray(11) = Button11
        bttonArray(12) = Button12
        bttonArray(13) = Button13
        bttonArray(14) = Button14
        bttonArray(15) = Button15
        bttonArray(16) = Button16
        bttonArray(17) = Button17
        bttonArray(18) = Button18
        bttonArray(19) = Button19
        bttonArray(20) = Button20
        bttonArray(21) = Button21
        bttonArray(22) = Button22
        bttonArray(23) = Button23
        bttonArray(24) = Button24
        bttonArray(25) = Button25
        bttonArray(26) = Button26
        bttonArray(27) = Button27
        bttonArray(28) = Button28
        bttonArray(29) = Button29
        bttonArray(30) = Button30
        bttonArray(31) = Button31
        bttonArray(32) = Button32
        bttonArray(33) = Button33
        bttonArray(34) = Button34
        bttonArray(35) = Button35
        bttonArray(36) = Button36
        bttonArray(37) = Button37
        bttonArray(38) = Button38
        bttonArray(39) = Button39
        bttonArray(40) = Button40
        For x = 1 To 40
            AddHandler bttonArray(x).Click, AddressOf Button_Click
            bttonArray(x).Show()
            bttonArray(x).Size = New Size(80, 23)
        Next x
  End Sub

   Rem button click sub
   Private Sub Button_Click(ByVal sender As Object, ByVal e As System.EventArgs)

        Rem now  i need to know then button number
        bttonArray(This number i need).Text = "click"
    End Sub

By sender reference,

CType(sender,Button).Text="Click"

Thank You for you quick reply.

It works , i see the clicked button change .
But i still not know how to get the number of the button.
I tryed several things but i keep freezing my program.
Can you maybe explain , how i can place the button number in a integer ?

By comparing references,

Dim btn As Button = CType(sender, Button)
        Dim i As Integer
        For i = 0 To bttonArray.Length - 1
            If btn.Equals(bttonArray(i)) Then
               'statements
            End If
        Next

EDIT:
variable name changed.

No i get "name c is not declared"

Im only programming in VB for a week
Im used to program on the AMIGA in GFAbasic
And i find VB very confusing
So this was a great help
Thank you very mutch

Sincerely yours

Jack

Thanks Jack. Purchase some good books of .net framework, and vb.net.

' ********************************************
' ** Button clicked so carry out the event **
' ********************************************

Private Sub btnEvents_Click(ByVal sender As System.Object, ByVal e As EventArgs) Handles MyBase.Click
         Dim cString As String = sender.Text()
        'Dim myObject As Object = sender


        Select Case cString
            Case "Add"
         ....
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.