40 CHAPTER 30 Extending ColdFusion with CFX
Aside from the name of the tag, the code is exactly the same as Listing 30.6 except that these lines:
// Convert the standard deviation to a string,
// then return it to the calling ColdFusion page
char result[20];
gcvt(dStdDev, 10, result);
pRequest->SetVariable( lpszVariable, result);
have been replaced with the following lines:
// Return statistics to the calling ColdFusion page
char result[20];
gcvt(dStdDev, 10, result);
pRequest->SetVariable(lpszVariable + “.StandardDeviation”, result);
gcvt(dVariance, 10, result);
pRequest->SetVariable(lpszVariable + “.Variance”, result);
gcvt(dMean, 10, result);
pRequest->SetVariable(lpszVariable + “.Mean”, result);
gcvt(dTotal, 10, result);
pRequest->SetVariable(lpszVariable + “.Sum”, result);
gcvt(iValueCount, 10, result);
pRequest->SetVariable(lpszVariable + “.Count”, result);
NOTE
Because it is a bit long and because all the other lines are the same, I am not including the <CFX_ComputeStatistics>
source code as a separate printed listing here. However, the Request2.cpp file is included with this chapter’s listings, and the
Windows-compiled version of the finished tag (
CFX_ComputeStatistics.dll) is included as well.
Listing 30.8 shows how the new <CFX_ComputeStatistics> tag can be used in a ColdFusion page.
The resulting Web page shows the number of data points, the average, the statistical variance, and
the standard deviation for each set of data (Figure 30.12). Note that either dots or square brackets
can be used to refer to the members of the returned structure, just like any other CFML structure.
Listing 30.8 ComputeStatisticsDemo.cfm—Using Structures Returned by a CFX Tag
<!---
Filename: ComputeStatisticsDemo.cfm
Author: Nate Weiss (NMW)
Purpose: Computes standard deviations
--->
<!---
Retrieve film information from database
--->
<cfquery datasource=”ows”
name=”GetFilms”>
SELECT * FROM Films
</cfquery>
<!---
Compute statistics for the ratings of each film
--->
<CFX_ComputeStatistics query=”GetFilms”
column=”RatingID”
variable=”FilmsStats”>
Commenti su questo manuale