0

hello friends
i cant find the solution to create control array in vb.net.for e.g i want to create calculator.it required so many buttons,take so many buttons ,give them a name and handle them at the time of coding is cumbersome task.so if we use button's array like in VB 6.0,by setting its index property.but in VB.net i couldnot find the index property at design time.can you pls help me to do this?

4
Contributors
3
Replies
10
Views
3 Years
Discussion Span
Last Post by Reverend Jim
0

Do something like this:

 Dim btnArray(10) As System.Windows.Forms.Button
 For i As Integer = 0 To 9
    btnArray(i) = New System.Windows.Forms.Button
 Next i
0

There are several examples in the Code Snippets including here. If you want to create an array of references to existing buttons then it helps to pick good names. For example, if you name your calculator digit buttons btn0 to btn9 then you can do

Private btnDigits() As Button (declared at the class level)
.
.
.
For i = 0 To 9
    btnDigits(i) = Me.Controls("btn" & i)
Next

Then you can create a common handler Sub instead of duplicating the code in ten different Click event handlers.

Edited by Reverend Jim

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.