Comparison Between VB 6.0 and VB .NET Objects, Part 2

In Part 1 of Comparison Between VB 6.0 and VB.NET Objects, you looked at the differences in the Properties Windows. This article, Part 2, compares the most obvious and common features between the VB 6.0 and VB.NET Toolboxes, based on these aspects:

  1. Toolbox Tabs
  2. Toolbox Tools
  3. Active X
  4. Control Arrays

ToolBox Tabs

The General tab of the Visual Basic 6.0 Toolbox displays the standard Visual Basic controls plus any ActiveX controls you have added to your project.

With the General tab, you can:

  • Display ToolTips for the Toolbox buttons: Select the Show ToolTips option in the General tab of the Tools, Options dialog box.


    Figure 1

  • Customize the Toolbox by adding tabs to it: Right Click anywhere on the Toolbox, to display Figure 2


    Figure 2

    Select Add Tab from the displayed menu, once clicked, a Dialog Box, similar to Figure 3, will be displayed.


    Figure 3

    Inside the above dialog box, you can enter a descriptive name for the new Toolbox tab.
    For example: Enter MDI in the New Tab Name dialog box.

    Repeat the previous steps for each new tab you want to add.
    For example: Enter DataBase Controls in the New Tab Name dialog box.

    Your Visual Basic 6.0 Toolbox should now look like Figure 4.


    Figure 4

  • Customize the General tab or a custom tab: Once all the necessary tabs are added to the Visual Basic 6.0 Toolbox, you now can add controls to the added tabs by selecting the Components command from the Project menu.

For the MDI Tab, you could include the following controls.

Microsoft Windows Common Controls 6.0 (SP4)

The following controls are contained within the Microsoft Windows Common Controls 6.0 (SP4) set of controls:

  • ImageList
  • ListView
  • ProgressBar
  • Slider
  • Status Bar
  • TabStrip
  • Toolbar
  • TreeView

Your MDI Toolbox tab should now look like that in Figure 5:


Figure 5

Note: If these controls were added to the General tab, you may need to drag these controls from the General tab to the MDI tab.

Feel free to experiment with adding controls to the DataBase tab. Some controls that you can be added to your DataBase tab are:

  1. Microsoft Data Bound List Controls 6.0: The following controls are contained within the Microsoft Data Bound List Controls 6.0 set of controls:
    • DBList
    • DBCombo
  2. Microsoft DataList Controls 6.0 (OLEDB): The following controls are contained within the Microsoft DataList Controls 6.0 (OLEDB) set of controls:
    • DataList
    • DataCombo
  3. Microsoft ADO Data Control 6.0 (OLEDB)
  4. Microsoft DataGrid Control 6.0 (OLEDB)
  5. Microsoft DataRepeater Control 6.0 (OLEDB)

Your toolbox should now look like Figure 6.


Figure 6

To rename and delete tabs from the Visual Basic 6.0 Toolbox, right-click on the Tab name, and choose the desired option from the displayed menu, as shown in Figure 7.


Figure 7

Toolbox Tools

Contols are the building blocks with which you assemble your Visual Basic 6.0 program. The Visual Basic 6.0 Toolbox is a palette of controls, and you build your user interface by selecting controls from the Visual Basic 6.0 Toolbox and placing them on your forms.


Figure 8

Some controls are built into Visual Basic 6.0 and can’t be removed from the Toolbox. These controls reside within Visual Basic 6.0 itself. These controls (as shown in Figure 8) are known as intrinsic controls. Other controls live outside Visual Basic 6.0 and reside in files that end with the extension .ocx. These controls are known as ActiveX controls, and can be added and removed from the Visual Basic 6.0 Toolbox—but more on that a little later.

For a detailed explanation of the Visual Basic 6.0 intrinsic controls, consult this Web page: Using the Standard Controls and more.

Active X Controls

that you can add to your Visual Basic 6.0 project.
Figure 14 Insertable objects, such as a Microsoft Excel Worksheet object, are components you can use as building blocks to build integrated solutions. An integrated solution can contain data in different formats, such as spreadsheets, bitmaps, and text, which were all created by different applications.

Control Arrays

A Control Array is an indexed group of similar controls that are of the same type and have the same name. Individual elements within the control array are identified by a unique index number.

Now, you can create a control array of CommandButtons.

Creating a Control Array

Method 1:

  • Add a CommandButton to your Form, and name it cmdCommandArray, for example.
  • Make sure that cmdCommandArray is selected. Choose Copy from the Edit menu (or right-click the obejct and select Copy) to copy the CommandButton to the Clipboard.
  • Choose Paste from the Edit menu (or right-click the Form and choose Paste). You’re presented with a dialog box asking whether you want to create a control array. Click Yes to create the control array.

Now that the control array is created, if you go to the Properties window and display the Object drop-down list, notice that there are now two (2) CommandButtons with the same name, cmdControlArray, each with its own subscript.

Method 2:

  • Add a CommandButton to your Form, and name it cmdCommandArray, for example.
  • Add a second CommandButton to your Form, and give it the same name (cmdCommandArray)
  • You’re presented with a dialog box asking whether you want to create a control array. Click Yes to create the control array.

Method 3:

  • Add a CommandButton to your Form, and name it cmdCommandArray, for example.
  • Change the CommandButton’s (cmdControlArray) Index Property to 0.
  • Change the CommandButton’s Caption to “Button 1”.
  • Press F7 to access the Code Window.
  • Edit your Form_Load event to resemble the following:
Private Sub Form_Load()    'Occurs when form is loaded into memory

   'Create a new CommandButton
   Load (cmdCommandArray(1))    'first object has a 0 based index,
                                'so 1 means "2"

   'Move the new button directly underneath the previous button
   'same left position on form
   cmdCommandArray(1).Left = cmdCommandArray(0).Left
   cmdCommandArray(1).Top  = cmdCommandArray(0).Top _
   + cmdCommandArray(0).Height    'directly underneath previous button

   cmdCommandArray(1).Caption = "Button 2"    'give unique caption

   'make the new button visible, without making it visible, the
   'object will exist only in memory, and not on screen
   cmdCommandArray(1).Visible = True

End Sub

By following Method 3, you now are able to dynamically add CommandButtons to the Control Array at run time. New controls are exact duplicates of the first control element of the control array. The values of all properties except Index and Visible are identical—including the values of Left and Top. Thus, when you create a new control, it will be placed right over the first control in the array. For the new control to coexist with other controls in the array, you must move the control to a new position.

When you run the code, notice that the program creates a new CommandButton on the form and places it just below the first.

Events for Control Arrays

All Control Array elements share the same event handler.

For example: Double-click your cmdCommandArray button on the form. Your Code Editor should now have a procedure similar to the following:

Private Sub cmdCommandArray_Click(ByVal Index As Integer)
End Sub

Notice the above Index argument, now included in the CommandButton’s event handler. This is how you distinguish between the elements of the control array, usually with a Select Case statement. A small example follows:

Private Sub cmdCommandArray_Click(ByVal Index As Integer)

Select Case Index    'determine which element was clicked on
   Case 0            'first button
      'indicate that first button was clicked
      MsgBox("First Button Clicked")
   Case 1            'second button
      'indicate that second button was clicked
       MsgBox("Second Button Clicked")
End Select

End Sub

When the above code is run, you will notice that you are able to click on both buttons, and both buttons display a different message, indicating which button was clicked.

Now, look at how the Visual Basic .NET Toolbox changed, and how you can accomplish the same functionalities.

More by Author

Must Read