Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

TextBox Arrays in Visual Basic.Net

Status
Not open for further replies.

Ken01

Programmer
Aug 8, 2014
62
GB
Hello
In VB6 and earlier versions it was possible to have arrays of Textboxes, e.g TextBox(0); TextBox(1) etc
which simplified the display of data from arrays or read from a file.
In Visual Basic.Net this feature doesn't seem to be available and I was wondering if there was any equivalent
way to do the same task without resorting to very extensive coding?
 
Well, there is something like that, but a little different :)

Let's say you have 2 option buttons (called here Radio Buttons): radAll and radCoRt (this is from my app, option 'All' and option 'County and Route') and you want to 'treat' them as an array (in CheckedChanged event):

Code:
Private Sub [blue]RadioButtons_CheckedChanged[/blue](ByVal sender As System.Object, _ 
    ByVal e As System.EventArgs) _[red]
    Handles radCoRt.CheckedChanged, radAll.CheckedChanged[/red]

If CType(sender, RadioButton).Checked = False Then Exit Sub

Me.Cursor = Cursors.WaitCursor

Select Case CType(sender, RadioButton).Name
    Case radAll.Name
        ...
    Case radCoRt.Name
       ...
End Select

Me.Cursor = Cursors.Default

End Sub

The [blue]BLUE[/blue] part of the code may be whatever you want, it is just a name of the procedure. The [red]RED[/red] part is what creates an 'array' (not really) of the controls.

Have fun.

---- Andy

A bus station is where a bus stops. A train station is where a train stops. On my desk, I have a work station.
 

It's still possible to have an array of not just textboxes, but any type of control. Just define the array as the type of the control, like so:

Dim TextBoxes() As TextBox

You can define the size of the array at creation:

Dim TextBoxes(5) As TextBox

Or you can use ReDim and ReDim Preserve to resize the array as needed at runtime.

I used to rock and roll every night and party every day. Then it was every other day. Now I'm lucky if I can find 30 minutes a week in which to get funky. - Homer Simpson

Arrrr, mateys! Ye needs ta be preparin' yerselves fer Talk Like a Pirate Day!
 
> Just define the array as the type of the control

That's not quite the same thing. An array of controls is not a control array (the latter being what the OP is asking about)

>this feature doesn't seem to be available

Sadly not. There was talk some years ago that Microsoft would bring the feature to VB.NET, but it never happened.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top