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

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

By Dan Mabbutt, About.com

8 of 8

Finishing up the code

Of the three final subroutines, only the first is interesting. (The last two are just the click events that call the add and delete subroutines.) The FlipPB subroutine isn't complex either. It just checks the value of the FaceUp property of the class, reverses it, and sets the color of the control accordingly.

~~~~~~~~~~~~~~~~~~~~~~~~~
Private Sub FlipPB(ByVal ID)
  PB(ID).FaceUp = Not PB(ID).FaceUp
  Select Case PB(ID).FaceUp
    Case True
    PB(ID).BackColor = Color.Blue
  Case False
    PB(ID).BackColor = Color.Red
  End Select
  PB(ID).BringToFront()
End Sub

Private Sub Button1_Click(ByVal sender As System.Object, _
  ByVal e As System.EventArgs) Handles Button1.Click
  Call AddToPB()
End Sub

Private Sub Button2_Click(ByVal sender As System.Object, _
  ByVal e As System.EventArgs) Handles Button2.Click
  Call RemoveFromPB()
End Sub
~~~~~~~~~~~~~~~~~~~~~~~~~

This method is an excellent study for learning about events, handlers, properties, classes and so forth, but copying of entire object arrays back and forth can cost a lot of CPU time, especially if you have a significant number of controls in the arrays. So this may not be the method of choice for all your programs. But it's a great piece of work anyway.

Thanks William!

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. Finishing up the code

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

All rights reserved.