Implementing a User Defined Type Property

Visual Basic 6 adds the user-defined type (UDT) to the list of data types a property can represent. However, its use isn't intuitive. Here are the steps needed to create a UDT property in VB6:






1. Declare a Public user-defined type definition.

2. Declare a Private member variable whose data type is that of the user-defined type.

3. Declare a Public Property Get procedure whose data type is that of the user-defined type.

4. The assignation within the Property Get procedure should be the Private member variable.

5. Declare a Public Property Let procedure. The data type of the value parameter is that of the user-defined type.

In addition, client applications using the UDT property can do so only by using early binding. See the section "Using ActiveX Components in a Project" later in this chapter for information about early binding.

Here's a quick example:

Server code:

Public Type udtTestType EmployeeNo As Integer EmployeeName As String End Type

Private mudtTestType As udtTestType

Public Property Get TestType() As udtTestType

TestType = mudtTestType End Property

Public Property Let TestType(udtVal As udtTestType)

mudtTestType = udtVal End Property

Client code:

Dim oServer As Server.ServerClass Dim oRemUDT As Server.udtTestType

Set oServer = New Server.ServerClass oRemUDT = oServer.TestType oRemUDT.EmployeeName = "Tim" oRemUDT.EmployeeNo = 1

oServer.TestType = oRemUDT

Set oServer = Nothing

60 Chapter 4 - Class Modules

To use remote user-defined types in this manner, you need a computer with NT4 and NT Service Pack 4 or above.

Was this article helpful?

0 0

Post a comment