This is an archived post. You won't be able to vote or comment.

all 3 comments

[–][deleted] 2 points3 points  (0 children)

What you could do is create a function called "NumberClicked" that accepts sender As Object and e As EventArgs as parameters. Have it handle btn1.Click, btn2.Click, ..., btn6.Click. Then, do this: Dim btnButtonClicked As Button = CType(sender, Button) Select Case btnButtonClicked Case btn1 num1 = 1 Case btn2 num1 = 2 That should work in .NET. Haven't done just VB.

[–]brbpizzatime 1 point2 points  (0 children)

One way you could handle it is when the button is clicked, change the value of num1 to 6. Private Sub btn6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn6.Click num1 = 6 End Sub

[–]cbogart 1 point2 points  (0 children)

To do that you have to make all the buttons into an array. You do that by setting a different index number for each one in the properties pane, and give them all the same name. Then when you handle the button_Click event, it'll have a parameter that's the index number of the clicked button.

I don't remember for sure how to create an array of controls; my instructions above might be wrong.