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?

Recommended Answers

All 3 Replies

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

can i see your vb.net interface?

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.