Ah you should not use the "me" in Buttons.
I've copied that from your message in the code, while I was not really
looking what you wrote.
Do you really think that you are the first one using this code by the way?
However, I tested it exactly as you did with one change.
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Dim Buttons() As Button = {Button1, Button2, Button3, Button4,
Button5, Button6}
For i = 0 To Buttons.Count - 1
Buttons(i).Text = "DS" & CStr(i + 1)
Next
End Sub
End Class
The Buttons on the form have now the text DS1 to DS6
Cor
"DanS" wrote in message
Dan the problem with this is that you can only do this like
you show if the button is in a button array.
Dim Buttons() as button =
{button1,button2,button3...........................button25)
For i = o to buttons.Count-1
me.Button(i).Text = stuff
next
Why does your code not run on my PC, even after I fix the
typing errors ?
I've got a form with six Buttons, Button1 through Button6, and
when I click Button1.....
Private Sub Button1_Click(ByVal sender As System.Object, ByVal
e As System.EventArgs) Handles Button1.Click
Dim Buttons() As Button = {Button1, Button2, Button3, Button4,
Button5, Button6}
Dim i As Integer
For i = 0 To Buttons.Count - 1
Me.Buttons(i).Text = "Changed Text" & i
Next
End Sub
Results in this error message:
Error 1 'Buttons' is not a member of
\WindowsApplication1.Form1'. C:\Documents and Settings\DS
\Local Settings\Application Data\Temporary Projects
\WindowsApplication1\Form1.vb 10 13 WindowsApplication1
I'm guessing it's because .Net doesn't support control arrays
the way VB6 does. From what I understand, you need to add the
controls to collectionn, and then you can access them in the
collection, sort of like a control array.
Please tell me I'm wrong and you're code works perfectly to do
what the OP wants.