VB6
beginners tutorial - Learn VB6
Advanced
VB6 tutorial - Learn Advanced VB6
Systems
Analysis - System analysis and Design tutorial for Software Engineering
|
You are here: Visual
Basic > Advanced VB6 tutorial
> Chapter 19
Setting Up a Sample Group
For the purposes of this demonstration, you will set up two projects: one standard
EXE that consists of a simple form with one command button, and one ActiveX DLL
project.
To create the sample projects, follow these steps:
STEP BY STEP
19.1 Setting Up Multiple Projects
-
Start Visual Basic. The Startup dialog box appears, as shown in Figure 19.7.

FIGURE 19.7. Selecting a new Standard EXE project through the Visual Basic
6 Startup dialog box.
NOTE - No Startup Dialog Box Appears at the Beginning of a VB Session:
If the dialog box shown in Figure 19.7 does not appear when you start Visual Basic
6, you have most likely chosen to turn it off, and a default, empty, project is
created instead. For the purposes of this example, the project created by default
will work just fine. If you wish to have the Startup dialog box appear when you
start Visual Basic in the future, you can turn it back on by selecting Prompt
For Project under the Environment tab in the Visual Basic Options dialog box,
as shown in Figure 19.8.

FIGURE 19.8 Control whether the Startup dialog box appears through this Option
dialog box.
-
From the dialog box, select the Standard EXE icon.
-
This project will include a single form, named Form1. Change the following
properties of Form1 to the indicated values:
• Change Name from "Form1" to
"frmSample".
• Change BorderStyle to 3
- Fixed Dialog.
-
On the form, create a new button. Change the button’s name to
cmdGetStatus, and its caption to "Get Status".
-
Place the following code into the form, replacing anything else that may be
there:
Option Explicit
Private Sub cmdGetStatus_Click()
Dim sTemp As String
Dim objStatus As New clsStatus
sTemp = objStatus.Status
MsgBox sTemp, vbOKOnly, "Status"
End Sub
The code itself is very straightforward: It takes a string value from the
objStatus object and displays it in a standard Visual Basic message box.
-
Change the name of the project to "Sample".
-
Add a second project by choosing Add Project from the File menu. Select ActiveX
DLL from the dialog box that appears, as shown in Figure 19.9.

FIGURE 19.9 Adding a new ActiveX DLL project to a project group.
-
The new project already contains one class module, Class 1, so you won’t
need to add anything. Change the class’s name to clsStatus in its Property
sheet; it is referred to it by that name in the cmdGetStatus_Click
routine in step 5.
-
Change the new project’s name to "DateTime".
-
Place the following code into clsStatus, once again
replacing any other code that may already be there:
Option Explicit
Public Property Get Status() As String
Dim sTemp As String
sTemp = Format(Date, "Long Date")
Status = "The Current Date is " & sTemp
End Property
This property procedure, like the preceding code sample, is simple. It puts together
a simple string and returns it to the calling program.
After you have completed all the preceding steps, the group is almost complete.
The code in your Get Status button won’t work, however, if you stop now.
(Try it, a User-Defined type not defined error will
appear when you click on the button.) You still need to add a reference to the
DLL to your main project so that you can create instances of your new class.
Adding a reference to a project that is in the same project group is not much
different from adding any other reference. It is, in fact, a little easier. If
you select the main project in the Project Explorer, and then choose the References
command from under the Project menu, the standard Visual Basic References dialog
box will appear, as shown in Figure 19.10.

FIGURE 19.10 ActiveX objects in the same project group appear at the top of
the unselected References list.
Note that the entry for your new project, DateTime,
appears directly under the existing, selected references and not in regular alphabetic
order. This is not a mistake. Microsoft expects you to commonly be making references
to other projects in the same project group. Because this is the main reason why
this feature exists, Microsoft has made it a little easier. Another important
fact here is that the DateTime DLL was never compiled,
but still appears in the list. This would not occur if you didn’t have the
projects in a group. After you check the DateTime reference
and close the dialog box, the main project will be ready to run.
<< Previous | Contents
| Next >>
|
|