Visual Basic Concepts
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
Option Explicit
' Reference to a Thing object.
Private mthTest As Thing
' 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
' 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.
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. |