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

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

By Dan Mabbutt, About.com

4 of 8

The "Control Array" is actually in the main program

To demonstrate William's solution, you first need a form with two buttons. One adds controls, the other removes them.

William's example starts out by adding four instances of the class. Each instance is saved in an array indexed by the ID variable. ID is one of the properties of each instance of the class.

The Dim for PB(0) creates the "control array" that will store our unique PictureBoxClass objects. The PBEmpty variable is just a "one time initialization flag" used to start things out right.

Here's the code to start William's demonstration program:

~~~~~~~~~~~~~~~~~~~~~~~~~
Dim PB(0) As PictureBoxClass
Dim PBEmpty As Boolean = True
Private Sub Form1_Load(ByVal sender As System.Object, _
  ByVal e As System.EventArgs) Handles MyBase.Load
  For a As Integer = 1 To 4
    Call AddToPB()
  Next a
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. The Control Array is actually in the main program

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

All rights reserved.