home account info subscribe login search FAQ/help site map contact us


 
Brief Full
 Advanced
      Search
 Search Tips
To access the contents, click the chapter and section titles.

Advanced Visual Basic Techniques
(Publisher: John Wiley & Sons, Inc.)
Author(s): Rod Stephens
ISBN: 0471188816
Publication Date: 06/01/97

Search this book:
 
Previous Table of Contents Next


Building the Client

The client application should run in a separate instance of the Visual Basic programming environment. The new client program will be very similar to the step 1 version. The main difference is that the new version does not include the server class. Instead, it creates an instance of the server class using the running server application.

Before a program can use a class provided by another application, the program must contain a reference to the other application. In Visual Basic 4, the References command in the Tools menu presents a list of the project’s references. In Visual Basic 5, the References command in the Project menu displays a similar list.

The running instance of the server application should be selected within the References list. This instance will have the name given to the server application—in this case, Time Manager.

When the server is highlighted, the References dialog will display the server’s location. For a server running in a Visual Basic development environment, the server’s location will end in “.vbp”—for example, C:\Ch11\Step2\Server\TimeSvr.vbp. Sometimes more than one server will be available. For example, the References dialog might list a Time Manager server with location C:\Ch11\Step2\Server\TimeSvr.exe. This is an executable program, not a server running in the Visual Basic development environment.

Occasionally a client’s References dialog will list a server as missing. This happens when a previously selected server executable is rebuilt. It also happens when a server running in the Visual Basic environment is started, selected in the client’s References dialog, stopped, and then restarted. The old version of the server is no longer running so the class references are out of date. In these cases, the client’s References dialog should be reopened and the new server selected.

Using CreateObject The client application can use the CreateObject function to create instances of an object supplied by a server. The following code shows how the TimeSync client creates an object of the TimeSetter class provided by the TimeManager server application.

Dim time_setter As Object

Private Sub Form_Load()
    Set time_setter = CreateObject(“TimeManager.TimeSetter”)
End Sub

Testing

At this point the client is ready for testing. When the client uses the methods of the server class object, the appropriate server code executes. Break points within the client and server code should be used to test the two programs thoroughly. Once the client and server are running on separate computers, debugging them becomes much more difficult.

Step 2 Summary

The following list shows the main steps for creating and testing the local client and server applications:

1.  Build the server.
a.  Move the server class into a new Sub Main application. The Main subroutine does not need to do anything, but it must exist in Visual Basic 4.
b.  Set project options. In Visual Basic 4, set Startup Form to Sub Main, StartMode to OLE Server, and set the project name. In Visual Basic 5, set the Project Type to ActiveX EXE and set the project name.
c.  Set the server class properties. In Visual Basic 4, set Public to true and Instancing to 1 - Creatable SingleUse or 2 - Creatable MultiUse. In Visual Basic 5 set Instancing to MultiUse (5)
d.  Run the server to add the server to the client’s references list.
2.  Build the client.
a.  Remove the server class from the client application.
b.  Invoke the References command and select the server.
c.  Run the client.
3.  Test the client and server thoroughly.

Step 3: Testing Remotely

After the client and server applications have been thoroughly tested on the same computer, it is time to test them across the network. Figure 11.7 shows the relationship between the client and server schematically. When the client references the svr object, the object is created in the server application on the remote computer. At this point, tracing the interactions between the client and server processes is more difficult than it is when the programs run on the same computer.

By now, most of the bugs should have been worked out of the client and server applications. Installing the server correctly is a complicated enough process without the extra bother of chasing application errors.

The following list shows the basic steps for installing and testing the remote server. The sections that follow explain each of these steps in detail.


Figure 11.7  The client and server programs running on different computers.

1.  Compile the server.
2.  On the server computer do the following:
a.  Install the server program.
b.  Register the server.
c.  Grant access to the server.
d.  Start the automation manager.
3.  On the client computer do the following:
a.  Register the server.
b.  Run the client.

Compile the Server

Compiling the server is easy. In Visual Basic 4, the Make EXE File command in the development environment’s File menu creates the server executable. In Visual Basic 5, the Make TimeSvr.exe command builds the executable.

If the server executable already exists, Visual Basic asks if it should replace the existing file. When it does attempt to replace the file, the system may generate a Permission Denied error. This can happen if an instance of the client is loaded in the Visual Basic development environment. Even though the client is not running, Visual Basic locks the server executable so it cannot be deleted and replaced. Unloading the client application by creating a new one or exiting Visual Basic will unlock the executable so it can be replaced.


Previous Table of Contents Next


Products |  Contact Us |  About Us |  Privacy  |  Ad Info  |  Home

Use of this site is subject to certain Terms & Conditions, Copyright © 1996-1999 EarthWeb Inc.
All rights reserved. Reproduction whole or in part in any form or medium without express written permision of EarthWeb is prohibited.