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


Generating Reports

When the ReportList client invokes the report server’s LoadReport subroutine, control passes to the server. The server activates a timer control to trigger the actual report generation later, and it quickly returns control to the client. This allows the client to continue operating asynchronously.

Scheduling the Report

At this point, control passes to the server object’s LoadReport subroutine. In the Query Server application, LoadReport creates the report and returns the results. The new version saves the parameters and callback object for later use, and it creates a WakeUpForm object. This form contains a single timer control named Waker. LoadReport enables Waker and then exits, returning control to the client application.

Public Sub LoadReport(params As String, cb As Object)
   ‘ Save the callback object.
   Set TheCallback = cb
 
   ‘ Save the parameter string.
   TheParams = params
 
   ‘ Create a new WakeUpForm.
   Set TheWakeUpForm = New WakeUpForm
 
   ‘ Tell it what report to wake up.
   Set TheWakeUpForm.ReportObject = Me
 
   ‘ Activate the timer.
   TheWakeUpForm.Waker.Enabled = True
End Sub

Now the client application has finished requesting the report. Because it has no code running, the client becomes idle. The user could request a new report and begin entering parameter values on a ParameterForm. The user could also invoke a menu command or close a previously generated report.

Something rather odd occurs if the user exits the application at this point. When the report server finishes creating the report, it invokes a callback object to display the results. If the client application has exited, the callback will still create a new form to display the report. Building that form will force the application to reopen the main MDI form so the report results can lie inside it. The MDI form’s Load event then causes the ReportListForm to present a list of available reports.

This behavior is decidedly strange. In other applications things might be even worse. For example, if the MDI form’s Load event required the user to enter a user name and password, the program could enter a very strange state. The report results might still appear, even though the application would not necessarily be logged in as the same user.

One way to prevent this sort of behavior would be to disable the Exit command as long as a server request was still running. When no such requests were outstanding, the Exit command would behave normally.

Starting the Report Object

WakeUpForm contains a single timer control named Waker. It also declares a form-level variable, Report-Object. The LoadReport subroutine described in the previous section saves a reference to a report object in this variable. When its Timer event occurs, Waker invokes this object’s MakeReport subroutine to produce the actual report.

Public ReportObject As Object

Private Sub Waker_Timer()
   ‘ Disable the timer so we don‘t trigger again.
   Waker.Enabled = False
 
   ‘ Wake up the report object.
   ReportObject.MakeReport
End Sub

Building the Report

The first thing the Report object’s MakeReport subroutine does is unload the WakeUpForm. As mentioned earlier, this is extremely important. A Visual Basic program will not stop as long as it has any form running. If this form is not unloaded, the server process will keep running even after the client has finished with it.

The task manager application on the server computer can determine whether a rogue server is running invisibly. In Windows 95, pressing Ctrl-Alt-Del presents a list of running tasks. If a server appears in the list, it may need to be stopped manually. Figure 13.5 shows the Windows 95 task manager.

It is important not to confuse a runaway server process with an instance of the Visual Basic development environment that is working with the server. The server project loaded into the development environment will be named “AsyncServer - Microsoft Visual Basic [design]” in the task list. If the program is running in the development environment, the last part of this name will be “[run]” instead of “[design].” If a running server has been interrupted in the development environment, this last part will be “[break].” In Figure 13.5 the highlighted task is an AsyncServer running normally as an independent executable program. The top line shows the AsyncServer program running in the Visual Basic development environment.

In Windows NT, double-clicking on the server computer’s screen background will bring up a task manager similar to the one shown in Figure 13.6. This task manager can also stop a runaway server.

After unloading the WakeUpForm, MakeReport must produce the actual report. The report parameters were stored in class variable TheParams by the LoadReport subroutine that created the WakeUpForm object.


FIGURE 13.5  The Windows 95 task manager.

Once the report is finished, MakeReport invokes the callback object’s DisplayReport subroutine to transfer the results back to the ReportList client application.


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.