Arrayed controls

  • Thread starter Thread starter Broadbent
  • Start date Start date
B

Broadbent

I have just started using VB7 so I am new to all this.
In VB6 I used to array controls, but I notice that there is no Index
property in the VB7 controls. What's the answer please?
 
Broadbent said:
I have just started using VB7 so I am new to all this.
In VB6 I used to array controls, but I notice that there is no
Index property in the VB7 controls. What's the answer please?

The former control arrays are not required anymore.

If you want to access controls by an index instead of by a more expressive
name, add them to an array:

dim m_labels() as label
'...
m_labels = new label(){lblName, lblStreet, lblWhatever}
 
Hi Broadbent

In addition to Ken

If you want it it is easy to make a control array here is a sample

\\\
Private myCheckbox(10) As CheckBox
Private Sub Form1_Load(ByVal sender As Object, _
ByVal e As System.EventArgs) Handles MyBase.Load
'you need for this to drag a groupbox1
'and a button on the form
Dim start As Integer = 4
Dim top As Integer = 18
Dim i As Integer
For i = 1 To 10
myCheckbox(i) = New CheckBox
myCheckbox(i).TextAlign = ContentAlignment.MiddleCenter
myCheckbox(i).Width = 40
myCheckbox(i).Height = 20
myCheckbox(i).Location = New System.Drawing.Point(start, top)
myCheckbox(i).Text = i.ToString
myCheckbox(i).Cursor = Cursors.Hand
Me.GroupBox1.Controls.Add(myCheckbox(i))
AddHandler myCheckbox(i).Click, AddressOf myCheckBox_Click
start = start + 40
If i = 5 Then
top = top + 20
start = 4
End If
Next
End Sub
Private Sub myCheckBox_Click _
(ByVal sender As Object, ByVal e As System.EventArgs)
Dim chk As CheckBox
chk = DirectCast(sender, CheckBox)
Dim i As String = chk.Text
End Sub
Private Sub Button1_Click _
(ByVal sender As Object, ByVal e As System.EventArgs) _
Handles Button1.Click
Dim a As New System.Text.StringBuilder
a.Remove(0, a.Length)
Dim i As Integer
For i = 1 To 10
If myCheckbox(i).Checked Then
a.Append(i.ToString)
End If
Next
MessageBox.Show(a.ToString)
End Sub
///

I hope this helps a little bit?

Cor
 
Back
Top