HDokes Posted July 1, 2003 Posted July 1, 2003 I have 99 buttons on a page of which I need to be able to perform a sweeping change of their .text and .tag properties. For convenience I have named the buttons "btnButton1" through "btnButton99". There are other buttons on the form I do not wish to change. I figure the easiest way to do this is through a routine as follows: dim x as int16 dim ButtonName as string for x = 1 to 99 ButtonName = "form.btnbutton" & ltrim(str(x)) ' set the specific button ButtonName.text = "sometext" ButtonName.tag = "sometag" next x Is something like this feasable in VB .NET? I realize that the variable at this time is a string and would have to have it's type changed to a control however I'm not sure if this can be done so that it is the content of the variable which is referenced as the control. Quote Thanks for any assistance provided and take care, Hdokes
Leaders dynamic_sysop Posted July 1, 2003 Leaders Posted July 1, 2003 Private Sub Button6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button6.Click Dim x As Control For Each x In Me.Controls If TypeOf x Is Button Then x.Text = "new text" End If Next End Sub if you wanted to make them all have a different name, you'd have to make a loop and a string as the button name or something. like this : Private Sub Button7_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button7.Click Dim arrButtons As New ArrayList() Dim i As Integer Dim strButton As String = "Button" Dim btn As Control For i = 0 To 6 arrButtons.Add(strButton & i) For Each btn In Me.Controls If btn.Name = arrButtons(i) Then btn.Text = "item: " & i End If Next Next End Sub Quote
HDokes Posted July 4, 2003 Author Posted July 4, 2003 Hi there, Thanks very much for the examples..... I applied the 2nd example and it is working like a charm! Quote Thanks for any assistance provided and take care, Hdokes
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.