Reputation: 113
I am a newbie in Visual Basic and I got stuck while trying to program a Tic Tac Toe game. I was trying to pass a variable as a parameter for a subroutine but I have no idea how. Here is my code.
Private Sub btn1_Click(sender As Object, e As EventArgs) Handles btn1.Click
ButtonDisable(btn1)
End Sub
Public Sub ButtonDisable(ByVal ButtonSelected As Object)
ButtonSelected.enable = False
End Sub
In the code, I am trying to disable btn1 by running the variable as a parameter in a subroutine. Every time I debug the program, Visual basic tells me "Public member 'enable' on type 'Button' not found."
Upvotes: 1
Views: 195
Reputation: 700272
The problem is that your parameter is of the type Object
, so inside the subroutine you can only use the members that are known to exist for Object
instances. Change the type to Button
, or the base class Control
, to access the members that are specific to buttons, or controls.
Public Sub ButtonDisable(ByVal ButtonSelected As Button)
ButtonSelected.Enabled = False
End Sub
Upvotes: 2