Control Arrays

  • Thread starter Thread starter Brian Shafer
  • Start date Start date
B

Brian Shafer

Hi,
I loved being about to use control arrays in vb classic. Doesn't look like
i can do this in vb.net?
Any input?
 
Hi Brian,

VB.NET and VB has the similar VB syntax, but the VB.NET is new designed
..NET programming language based on CLR.
The control array is no longer supported in VB.NET.
Here is link for your reference.

Control Array Changes in Visual Basic .NET
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vbcon/html/
vbconcontrolarraychangesinvisualbasicnet.asp


Best regards,

Peter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.
 
Hello, Brian,

I also thought that I would miss this feature. I was wrong!

In .Net you can use arrays or collections of controls. I think that
once you get into it you will find this is more versatile than the old
VB "control arrays".

One reason that I used to like the old VB control arrays was the ability
it gave to use the same event handler for a number of controls. In .Net
you can not only assign the same event handler to multiple controls, but
(unlike with the old VB control arrays) the controls can be of diverse
types. So for example, you can have the same handler deal with text
changes in a TextBox or a ComboBox.

Cheers,
Randy
 
Private myButtons As Button() = {Button1, Button2}

Private Sub Form_Load(...)
For Each btn As Button In myButtons
AddHandler btn.Click, AddressOf myButtons_Click
Next btn
End Sub

or

Private Sub myButtons_Click(...) Handles Button1.Click, Button2.Click
....
End Sub
 
Back
Top