name is not a member?

papimann

New member
Joined
Aug 4, 2009
Messages
1
Programming Experience
Beginner
Dim ctrl As Control

Private Sub correctenabledstate(ByVal x As Boolean)

For Each ctrl In Me.Controls

If TypeOf (ctrl) Is Button And ctrl.name <> "btnnewgame" Then

ctrl.Enabled = x

End If

Next

End Sub


this is the code i have written but it says that name is not a member of system.windows.forms.control please help ASAP
 
If you don't specify a type the Object type is assumed, and Object doesn't have a Name property.
VB.NET:
For Each ctrl [COLOR="Green"]As Control[/COLOR] In Me.Controls
You can also do this:
VB.NET:
Me.Controls("btnnewgame").Enabled = x
 
What JohnH says is correct but it actually doesn't apply here, given that you have declared the 'ctrl' variable as type Control. This is evidenced by the fact that the error message refers to the Control type. Are you absolutely sure that that's what the error says because that's obviously false, i.e. Name IS a member of System.Windows.Forms.Control.

Also, your test for the control being a Button is pointless. Are you actually going to have a control of any other type with that name? If the name is uniquely identifying then why test anything else?
 
Back
Top