I assume you wanted VB.NET. If not, I can provide a better answer in C# if you need it.
Try this: For Each button In (From x In Me.GetAllControls(Me).OfType(Of Button)() _ Where x.Name = "Button" & n _ Select x) button.Text = t Next You need to define this function: Private Function GetAllControls(ByVal control As Control) As IEnumerable(Of Control) Dim r = New List(Of Control) r.Add(control) For Each c In control.Controls r.AddRange(GetAllControls(c)) Next Return r End Function From: ozdotnet-boun...@ozdotnet.com [mailto:ozdotnet-boun...@ozdotnet.com] On Behalf Of Anthony Mayan Sent: Tuesday, 26 July 2011 12:47 To: ozDotNet Subject: Set property of texbox by name I have a form with many buttons. I want to be able to set the text property of the textbox at runtime by string. ("Button" & i).Text = "Hello" 'Of course this doesn't work...how do i replicate this correctly i a variable eg if i=1 then i want the code to do button1.text="Hello" if i=2 then i want the code to do button2.text="Hello" any suggest