![]() | |
|
|
|
To access the contents, click the chapter and section titles.
Advanced Visual Basic Techniques
Building the ClientThe 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 projects 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 applicationin this case, Time Manager. When the server is highlighted, the References dialog will display the servers location. For a server running in a Visual Basic development environment, the servers location will end in .vbpfor 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 clients 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 clients 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 clients 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
TestingAt 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 SummaryThe following list shows the main steps for creating and testing the local client and server applications:
Step 3: Testing RemotelyAfter 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.
Compile the ServerCompiling the server is easy. In Visual Basic 4, the Make EXE File command in the development environments 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.
|
|
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.
|