1. Home
  2. Computing & Technology
  3. Visual Basic

VB.NET: What Happened to Control Arrays!!! (Part 5)

By Dan Mabbutt, About.com

5 of 8

Adding and Deleting "Control Array" Elements - The AddToPB subroutine

The code that adds and deletes instances of the class from the array is as critical as the class coding. In fact, it seems to me that at least half of the magic happens in this part of the program.

~~~~~~~~~~~~~~~~~~~~~~~~~
Private Sub AddToPB()
  Dim a As Integer
  If PBEmpty = False Then
    a = PB.Length - 1
    Dim temp(a) As PictureBoxClass
    PB.CopyTo(temp, 0)
    a += 1
    ReDim PB(a)
    temp.CopyTo(PB, 0)
  Else
    a = 0
    PBEmpty = False
  End If
  PB(a) = New PictureBoxClass
  With PB(a)
    .ID = a
    .Height = 50
    .Width = 50
    .FaceUp = False
    .BackColor = Color.Red
    .Top = PB(a).Height * a / 2
    .Left = PB(a).Width * a / 2
    .Visible = True
    .BringToFront()
    AddHandler PB(a).PicBoxClick, _
      AddressOf FlipPB
    Me.Controls.Add(PB(a))
  End With
End Sub
~~~~~~~~~~~~~~~~~~~~~~~~~

Explore Visual Basic
By Category
About.com Special Features

Stay connected and entertained with reviews on tips on the latest HDTVs, cellphones and more. More >

Easy ways to connect two computers for networking purposes. More >

  1. Home
  2. Computing & Technology
  3. Visual Basic
  4. Using VB.NET
  5. Adding and Deleting Control Array Elements

©2009 About.com, a part of The New York Times Company.

All rights reserved.