Freigeben über


Visual Basic Concepts

Creating and Testing Thing Objects

To test a class — in this case, the Thing class — your test project must request that the component create an object from the class.

Note   This topic is part of a series that walks you through creating a sample ActiveX DLL. It begins with the topic Creating an ActiveX DLL.

Resize Form1 in the test project and place five command buttons and a check box on it, as shown in Figure 2.2. If you have never created a form in Visual Basic, see "Developing an Application in Visual Basic" in the Visual Basic Programmer’s Guide.

Figure 2.2   The test form for the Thing class

The following table lists the property values you need to set.

Object Property Setting
Form Caption Thing Demo
Command1 Caption Create New Thing
Command2 Caption Show the Thing
Command3 Caption Reverse the Thing’s Name
Command4 Caption Release the Thing
Command5 Caption Temporary Thing
Check1 Caption Stuck on itself

To add code to create a Thing and call its properties and methods

  1. Place the following code in the Declarations section of the test application’s form module:

    Option Explicit
    ' Reference to a Thing object.
    Private mthTest As Thing
    
  2. In the Object box, select Command1. Add the following code to the Click event procedure:

    ' Button "Create New Thing".
    Private Sub Command1_Click()
       Set mthTest = New Thing
       mthTest.Name = _
          InputBox("Enter a name for the Thing", _
          "Test Thing")
    End Sub
    
  3. In similar fashion, add the following code to the Click event procedures of Command2, Command3, and Command4:

    ' Button "Show the Thing".
    Private Sub Command2_Click()
       MsgBox "Name: " & mthTest.Name, , _
          "Thing " & mthTest.DebugID
    End Sub
    
    ' Button "Reverse the Thing's Name".
    Private Sub Command3_Click()
       mthTest.ReverseName
       ' Click "Show the Thing" by setting its Value.
       Command2.Value = True
    End Sub
    
    ' Button "Release the Thing".
    Private Sub Command4_Click()
       Set mthTest = Nothing
    End Sub
    

You don’t need to add code for Command5 or the check box yet.

Step by Step

This topic is part of a series that walks you through creating a sample ActiveX DLL.

To See
Go to the next step Running the TestThing Test Application
Start from the beginning Creating an ActiveX DLL.