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
news:Xns9E0987C6DEAEBthisnthatroadrunnern@216.196.97.131...
"Cor" <(E-Mail Removed)> wrote in
news:4cac4363$0$8913$(E-Mail Removed):
> 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.
>
> Otherwise you have, because a button can placed on any
> other container, to do it recursive
>
> Have for that recursive a look at this tip
> http://www.vb-tips.com/ClearTextBox.aspx
>
> Success
>
> Cor
>
> "Dan Smith" wrote in message
> news:(E-Mail Removed)...
>
> I have a form with 25 buttons and on load I would like to
> change the text of each button to unique names. A loop
> would work perfectly but obviously for i = 1 to 25
> me.button(i).text = stuff
> end for
>
> doesn't work. Anyone know of a easy way of doing this?
>
> Thanks
>
> Submitted via EggHeadCafe - Software Developer Portal of
> Choice ComponentOne Studio for ASP.NET AJAX - Free License
> Giveaway
> http://www.eggheadcafe.com/tutorials...98ce1f-2b5d-4e
> c8-b6d5-a1049651514e/componentone-studio-for-aspnet-ajax--fr
> ee-license-giveaway.aspx
>
>