Indexed Objects

In good old VB 6.0 and earlier versions object could be indexed, i.e. checkbox(1), textbox(5), etc.

Needless to say how useful indexed objects were for programming purposes, however on VB 2005 it seems (I, of course might be wrong) object can't be indexed.

Can anybody prove me I'm wrong, and if so, please show me how ?

Regards

Carlos

[373 byte] By [CarlosPereda] at [2008-1-10]
# 1

Code Snippet

Dim TB(4) as TextBox

Public SomeSum()

For I as Integer = 0 to 4

Dim NewTB as New Textbox()

NewTB.Name = "Textbox" & I.ToString()

TB(i) = NewTB

Next

End Sub

TaDa at 2007-10-3 > top of Msdn Tech,Visual Basic,Visual Basic Language...
# 2
You can index controls with the Me.Controls() property. They are not sorted by type however. For that, you can make your own index:

Public Class Form1
Private mTextBoxes() As TextBox

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
mTextBoxes = New TextBox() {TextBox1, TextBox2, TextBox3}
mTextBoxes(0).Text = "Nobugz"
mTextBoxes(1).Text = "waz"
mTextBoxes(2).Text = "here"
End Sub
End Class

nobugz at 2007-10-3 > top of Msdn Tech,Visual Basic,Visual Basic Language...
# 3

Thanks guys, it worked, however I still don't understand why we now have to workaround when we had it for granted. !!

CarlosPereda at 2007-10-3 > top of Msdn Tech,Visual Basic,Visual Basic Language...