Visual Basic Concepts

Remoting Features of Visual Basic

"Remoting" is the process of passing parameters between two different processes, usually across a network. For example, imagine a three-tier system. On the client machine, the application makes a call for data, passing several parameters as the criteria. On the middle-tier machine, an ActiveX EXE accepts the call and uses the criteria for retrieving the data.

For example, code on a middle-tier application might resemble:

Option Explicit

' This code is in a code module.
Public Type udtMyType ' Definition of a Public UDT
   birthDate As Date
   lastName As String
   firstName As String
   address As String
End Type

Public Function passUDT(myrec As udtMyType) As udtMyType
   ' Modify the data somehow.
   passUDT = myrec ' Return the UDT.
End Function

While code on the client machine that calls the function would be:

Option Explicit
Private myrec As udtMyType

Private Sub Command1_Click()
   Dim x As udtMyType
   x = passUDT(myrec)
   ' Do something with the UDT data.
End Sub

Passing a UDT as a Parameter of a Public Sub

While passing parameters has always been possible in previous versions of Visual Basic, passing user-defined types (UDTs) as parameters of public subs has not. This is now possible, as shown in the example above.

Performance Considerations

The cost of passing parameters out-of-process is far higher than passing them in-process. When passing a parameter, the data must be marshaled and passed to the external process. The code to accomplish this action can be expensive, but Visual Basic conceals this cost. The advantage of remoting data, however, is to create code that is easily comprehensible. Depending on the size of the UDT, it may also be easier to maintain than an ADO Recordset object.

*For More Information* For details about creating and using UDTs, see Creating Your Own Data Types.

Remoting ADO Recordsets

ADO Recordset objects can also be remoted. With this capability, ADO recordsets are especially suited for use on intranet and Internet client-server applications. For example, you can create an HTML or DHTML page that accesses data across the Internet from a web server application. When creating the HTML page, you can include the Microsoft ActiveX Data Access Recordset 2.0 Library, which features only the Recordset object. Since that library doesn't include the Command, Connection, and Parameter objects, your application will have the smallest possible footprint while retaining the functionality of the ADO Recordset features. The code below shows an example of remoting ADO recordsets.

' This code is in a code module.
' Set a reference to the Microsoft ActiveX Data Objects 2.0 Library
Private MyADORecordset As ADODB.Recordset

Public Function GetCustomer(LastName As String) As ADODB.Recordset
   ' Query the DB
   MyADORecordset.Open "SELECT * FROM Customers WHERE " & _
   "LastName = '" & LastName & "'", cn, adOpenForwardOnly, adLockReadOnly
   Set MyADORecordset.ActiveConnection = Nothing
   Set GetCustomer = MyADORecordset ' Return the recordset.
End Function

While code on the client machine that calls the function would be:

Option Explicit
Private SomeServer As Object

Private Sub Command1_Click()
   ' Client can use the lighter ADOR library. Set a reference to
   ' the Microsoft ActiveX Data Objects Recordset 2.0 Library.
   Dim MyData As ADOR.Recordset
   Set SomeServer = CreateObject("", myserver)
   Set MyData = SomeServer.GetCustomer("Smith")
   ' Do something with the data.
End Sub