VB6 beginners tutorial - Learn VB6

Advanced VB6 tutorial - Learn Advanced VB6

VB .NET - Learn Visual Basic .NET

Systems Analysis - System analysis and Design tutorial for Software Engineering

You are here: Visual Basic > Advanced VB6 tutorial > Chapter 12

Overview of COM Component Programming

Recall the syntax you saw in the preceding chapter for instantiating ActiveX objects in a client application:

Dim xl as Excel.Application


set xl = CreateObject("Excel.Application")


set xl = GetObject(,"Excel.Application")

Some server components (including any server components that you create with VB) support Microsoft's recommended standard, Dim As New. Assuming you had created a server component MyServer with a class MyClass, you could set up an object variable reference to the server component class with the line:

Dim objSvr As New MyServer.MyClass

This is the only line of code you would need, because the As New keyword declares and instantiates the object variable in a single line of code.

A somewhat more resource-efficient way to use the New keyword would be to declare the object variable without the New keyword, only using New when you're ready to use the object in code:

Dim objSvr As MyServer.MyClass
'Later in code:
Set objSvr = New MyServer.MyClass

This means that the resources to instantiate the object would not be required until the time that the object was actually needed.

The common thread in each of these sample lines is the servername. classname syntax you use when referring to your server component class.

The preceding statements that reference the system name of the server component and its class (Excel.Application or MyServer.MyClass) assume that you have already set a reference to the server component in the client project.

In this chapter, you see how to create, test, and maintain server components that can behave as Excel.Application did in the examples from Chapter 13.


<< Previous | Contents | Next >>

Home | About Us | Privacy Policy | Contact Us

Copyright © | All Rights Reserved