2025-04-27 07:49:33 -04:00

661 lines
42 KiB
HTML
Raw Blame History

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML dir=ltr><HEAD><TITLE>Module 2: Using COM Components</TITLE>
<SCRIPT language=JavaScript>
<!--
TempString = navigator.appVersion
if (navigator.appName == "Microsoft Internet Explorer"){
// Check to see if browser is Microsoft
if (TempString.indexOf ("4.") >= 0){
// Check to see if it is IE 4
document.writeln('<link rel="stylesheet" type="text/css" href="/iishelp/common/coua.css">');
}
else {
document.writeln('<link rel="stylesheet" type="text/css" href="/iishelp/common/cocss.css">');
}
}
else if (navigator.appName == "Netscape") {
// Check to see if browser is Netscape
document.writeln('<link rel="stylesheet" type="text/css" href="/iishelp/common/coua.css">');
}
else
document.writeln('<link rel="stylesheet" type="text/css" href="/iishelp/common/cocss.css">');
//-->
</SCRIPT>
<SCRIPT language=VBScript>
<!--
Sub Window_OnLoad()
Dim frmContents
On Error Resume Next
If Not Parent Is Nothing Then
Set frmContents = Parent.Contents
If Not frmContents Is Nothing Then
frmContents.Window.TOCSynch_Click
End If
End If
End Sub
//-->
</SCRIPT>
<META
content="This is an Active Server Pages (ASP) tutorial where you can lean how to use COM components to extend your scripting capabilities. In this module, you use COM components that are included with ASP to activate a sample Web site and query a database."
name=DESCRIPTION>
<META content="text/html; charset=Windows-1252" http-equiv=Content-Type>
<META content="Microsoft FrontPage 4.0" name=GENERATOR></HEAD>
<BODY bgColor=#ffffff text=#000000><FONT face=Verdana,Arial,Helvetica>
<H1><A name=module1>Module 2: Using COM Components in ASP Pages</A></H1>
<P>Using Microsoft&reg; Component Object Model (COM) components in your ASP pages can
dramatically extend the power that ASP already offers. COM components are pieces of compiled code that can
be called from ASP pages. COM components are secure,
compact, reusable objects that are compiled as DLLs and can be written in
Microsoft Visual C++&reg;, Microsoft Visual Basic&reg;, or any language that supports COM. For example, Microsoft
ActiveX&reg; Data Objects (ADO), which are used in Module 1 of this tutorial, provides you with methods and
properties to efficiently query databases. By using ADO, you don't have to write your own
complex data access code because ADO objects are built using COM components. </P>
<P>In this module, you use COM components that are included with ASP, and you also have a chance to write one
of your own.
This module shows how to develop an ASP page that delivers services useful
in e-commerce and includes the following lessons: </P>
<UL>
<LI><A
href="#rotating">Lesson
1: Rotating Advertisements</A>&nbsp;&nbsp;&nbsp;Rotate ads on a Web page, record user data, and
redirect users when advertisements are clicked on.
<LI><A
href="#counting">Lesson
2: Counting Page Hits</A>&nbsp;&nbsp;&nbsp;Track the number of times users request a page.
<LI><A
href="#creating">Lesson
3: Creating a Visual Basic COM Object</A>&nbsp;&nbsp;&nbsp;Create your own ActiveX object using
Microsoft Visual Basic.
<LI><A
href="#creatingj">Lesson
4: Creating a Java COM Object</A>&nbsp;&nbsp;&nbsp;Create your own Java object using Microsoft
Visual J++&reg;. </LI></UL><BR>
<H2><A name=rotating>Lesson 1: Rotating Advertisements</A></H2>
<P>Advertising is big business on the Web. This lesson describes how to use the
Ad Rotator component, installed with IIS, to rotate advertisements on your Web
pages. The Ad Rotator component selects an advertisement for your Web page each
time the user loads or refreshes the Web page. Furthermore, if you want to
change an advertisement, you only need to change it in the redirection and
rotation schedule files, instead of changing all the ASP files that contain the
advertisement. This saves development time if the advertisement appears on
numerous pages within your Web site. </P>
<P>Two files are required to set up the Ad Rotator component: a redirection
file, which contains URL links to ads, and a rotation schedule file, which
contains display data. By setting up these two files, the Ad Rotator component
can be called by any ASP page on your Web site. </P>
<P>In this lesson you perform the following tasks: </P>
<UL>
<LI><b>Example 1</b>&nbsp;&nbsp; Create an Ad Rotator rotation schedule file that creates ad-image links on
any page that calls this file.
<LI><b>Example 2</b>&nbsp;&nbsp; Create an Ad Rotator redirection file that specifies global ad-display
data and information specific to each advertisement.
<LI><b>Example 3</b>&nbsp;&nbsp; Create an include file to hold your Ad
Rotator calling code.
<LI><b>Example 4</b>&nbsp;&nbsp; Test the Ad Rotator by creating an ASP page that calls the Ad Rotator
component to display and rotate ads. This example requires that examples 1, 2,
and 3 are completed first. </LI></UL>
<P>
<H3>Example 1: Create an Ad Rotator Rotation Schedule File</H3>
<P>A rotation schedule file is used to catalog information about the ads you
want to display, including redirection information after the advertisement is
clicked on, the size of the displayed advertisement, the image to display, a
comment for the advertisement, and a number that indicates how often a
particular advertisement is chosen. When methods of the Ad Rotator component are
called in an ASP page, the component uses this file to select an advertisement
to display. </P>
<P>The rotation schedule file is divided into two sections that are separated by
an asterisk (*). The first section provides information common to all the ads,
and the second section lists specific data for each ad. To test the rotation
schedule file, you will use some images from Microsoft.com for your ad images.
The following list outlines the structure of the rotation schedule file: </P>
<h5>Section 1</h5>
<UL>
<LI><B>Redirection</B>&nbsp;&nbsp;&nbsp;In URL form, the path and name of the ASP file that
can be executed before showing an advertisement. This file can be used to record
information about the user who clicks on your ad. You can record information such as the client's IP address, what page the client
saw the advertisement on, how often an advertisement was clicked on, and so forth. This ASP
file can also handle the case where there is no URL associated with any
advertisement in Section 2. When charging advertisers for each hit on their
advertisement, it is good practice to prove to them that all the hits aren't resulting from the same user repeatedly hitting <B>Refresh</B>.
<LI><B>Width</B>&nbsp;&nbsp;&nbsp;The width of each ad image, in pixels. The default is 440.
<LI><B>Height</B>&nbsp;&nbsp;&nbsp;The height of each ad image, in pixels. The default is 60.
<LI><B>Border</B>&nbsp;&nbsp;&nbsp;The border thickness around each ad image. The default is 1.
<LI><B>Asterisk (*)</B>&nbsp;&nbsp;&nbsp;Separates the first section from the second section. This character must be on
a line by itself. </LI></UL>
<h5>Section 2</h5>
<P>You need to complete the following for each advertisement:
<UL>
<LI><B>Image URL</B>&nbsp;&nbsp;&nbsp;The virtual path and filename of the image file for the
advertisement.
<LI><B>Advertiser's Home URL</B>&nbsp;&nbsp;&nbsp;The URL to jump to when this link is
selected. If there is no link, use a hyphen (-).
<LI><B>Text</B>&nbsp;&nbsp;&nbsp;The text to display if the browser does not support graphics.
<LI><B>Impressions</B>&nbsp;&nbsp;&nbsp;An integer indicating the relative weight to give to
this ad when the Ad Rotator component selects an advertisement. For example,
if you list two advertisements, an ad given an impression of 3 has a 30%
probability of being selected while an ad given an impression of 7 has a 70%
probability of being selected. In this example, the Ad Rotator component
selects the Microsoft Windows&reg; advertisement two times out of five and the
Microsoft Office advertisement is selected three times out of five. </LI></UL>
<P>Copy and paste the following code in your text editor, and save the file as
<B>MyAdRot.txt</B> in the <I>x</I>:\Inetpub\Wwwroot\Tutorial directory.
</P><CODE>
<P>&nbsp; REDIRECT AdRotRedirect.asp <BR>&nbsp; WIDTH 250 <BR>&nbsp; HEIGHT 60
<BR>&nbsp; BORDER 0 <BR>&nbsp; * <BR>&nbsp; http://www.microsoft.com/windows/images/bnrWinfam.gif <BR>&nbsp;
http://www.microsoft.com/windows <BR>&nbsp; Microsoft Windows <BR>&nbsp; 2
<BR>&nbsp; http://www.microsoft.com/office/images/office_logo.gif <BR>&nbsp;
http://www.microsoft.com/office <BR>&nbsp; Office 2000 <BR>&nbsp; 3 </P>
<P>&nbsp; </P></CODE>
<h3>Example 2: Create an Ad Rotator Redirection File
</h3>
<P> When a user clicks on an advertisement, an Ad Rotator redirection file
written in ASP can capture some
information before showing the advertisement and write that information to a
file.&nbsp;
</P>
<P> For this to work, the <I>x</I>:\InetPub\Wwwroot\Tutorial folder must give
Read/Write access to the IUSR_<I>ComputerName</I> and IWAM_<I>ComputerName</I>
accounts. Alternatively, you can write this information to a Microsoft Access database
using the code from <A href="ASPTut01.htm#creating">Lesson 3 in Module 1</a> of this tutorial.
</P>
<P>Copy and paste the following code in your text editor, and save the file as
<B>AdRotRedirect.asp</B> in the <I>x</I>:\Inetpub\Wwwroot\Tutorial directory.
</P><CODE>
<P>&nbsp; &lt;%@ Language=VBScript %&gt; <BR><BR>&nbsp; &lt;html&gt; <BR>&nbsp;
&lt;head&gt; <BR>&nbsp; &lt;title&gt;AdRotRedirect file&lt;/title&gt; <BR>&nbsp;
&lt;/head&gt; <BR>&nbsp; &lt;body&gt; <BR><BR>&nbsp; &lt;% <BR>&nbsp;&nbsp;
'Create some variables. <BR>&nbsp;&nbsp; dim strLogFile <BR><BR>&nbsp;&nbsp;
'Get the physical path of this Web directory so that we know the path exists.
<BR>&nbsp;&nbsp; 'The ASP Server object has many useful methods. <BR>&nbsp;&nbsp; strLogFile = Server.MapPath(".") &amp;
"\AdRotLog.txt" <BR><BR>&nbsp;&nbsp; 'Set some constants for working with files.
<BR>&nbsp;&nbsp; Const cForAppending = 8 <BR>&nbsp;&nbsp; Const
cTristateUseDefault = -2 <BR><BR>&nbsp;&nbsp; 'Create a FileSystemObject object,
<BR>&nbsp;&nbsp; ' which gives you access to files and folders on the system.
<BR>&nbsp;&nbsp; Set fsoObject =
Server.CreateObject("Scripting.FileSystemObject") <BR><BR>&nbsp;&nbsp; 'Open a
handle to the file. <BR>&nbsp;&nbsp; 'True means that the file will be created
if it doesn't already exist. <BR>&nbsp;&nbsp; Set tsObject =
fsoObject.OpenTextFile(strLogFile, cForAppending, True) <BR><BR>&nbsp;&nbsp;
'Record the data for the user who has just clicked on an advertisement.
<BR>&nbsp;&nbsp; 'We have used the Write method of the ASP Request object.
<BR>&nbsp;&nbsp; 'The ServerVariables collection of the ASP Request object holds vast&nbsp; <BR>&nbsp;&nbsp; ' amounts of data for
each request made to a Web server. <BR>&nbsp;&nbsp;
tsObject.WriteLine "--------------------" <BR>&nbsp;&nbsp; tsObject.WriteLine
Date &amp; ", " &amp; Time <BR>&nbsp;&nbsp; tsObject.WriteLine
Request.ServerVariables("LOGON_USER") <BR>&nbsp;&nbsp; tsObject.WriteLine
Request.ServerVariables("REMOTE_ADDR") <BR>&nbsp;&nbsp; tsObject.WriteLine
Request.QueryString("url") <BR>&nbsp;&nbsp; tsObject.WriteLine
Request.ServerVariables("HTTP_REFERER") <BR>&nbsp;&nbsp; tsObject.WriteLine
Request.ServerVariables("HTTP_USER_AGENT") <BR>&nbsp;&nbsp; tsObject.Close
<BR><BR>&nbsp;&nbsp; 'Redirect to the Advertiser's Web site using the Redirect
method <BR>&nbsp;&nbsp; ' of the ASP Response object. <BR>&nbsp;&nbsp; 'When the
AdRotator component calls AdRotRedirect.asp, it&nbsp; <BR>&nbsp;&nbsp; '
automatically passes in the advertiser's URL in the QueryString.
<BR>&nbsp;&nbsp; Response.Redirect Request.QueryString("url") <BR>&nbsp; %&gt;
<BR><BR>&nbsp; &lt;/body&gt; <BR>&nbsp; &lt;/html&gt; </P></CODE>
<P>&nbsp;
</P>
<h3>Example 3: Create an Ad Rotator Include File
</h3>
<P>Include files are used to store any code that will be used by more than one
ASP or HTML file. It makes sense to put your Ad Rotator code into a simple
function in an include file. With an Ad Rotator include file, you need to
make only one function call from any ASP or HTML file when you want to display an
advertisement. Alternatively, you can put the code from the include file in every ASP file where you
plan to show an advertisement. However, if you want to change that code, you
have to make the change in every ASP file instead of in one include file.
</P>
<P>In this example, you create an Ad Rotator include file containing a function
named <b>GetAd</b>. This function randomly selects ads to display on your ASP pages.
</P>
<P>Copy and paste the following code in your text editor, and save the file as
<B>AdRotatorLogic.inc</B> in the <I>x</I>:\Inetpub\Wwwroot\Tutorial directory.
</P><CODE>
<P>&nbsp; &lt;% <BR>&nbsp;&nbsp; Function GetAd()
<BR><BR>&nbsp;&nbsp;&nbsp;&nbsp; dim objLoad <BR><BR>&nbsp;&nbsp;&nbsp;&nbsp;
'Create an instance of the AdRotator component. <BR>&nbsp;&nbsp;&nbsp;&nbsp; Set
objLoad = Server.CreateObject("MSWC.AdRotator") <BR><BR>&nbsp;&nbsp;&nbsp;&nbsp;
'Set the TargetFrame property, if any. If you have a Web
<BR>&nbsp;&nbsp;&nbsp;&nbsp; ' page using frames, this is the frame where the
URL opens. <BR>&nbsp;&nbsp;&nbsp;&nbsp; 'If the HTML page does not find the
TARGET name, <BR>&nbsp;&nbsp;&nbsp;&nbsp; ' the URL will be opened in a new
window. <BR>&nbsp;&nbsp;&nbsp;&nbsp; objLoad.TargetFrame = "TARGET=new"
<BR><BR>&nbsp;&nbsp;&nbsp;&nbsp; 'Set one of the other AdRotator properties.
<BR>&nbsp;&nbsp;&nbsp;&nbsp; objLoad.Border = 1 <BR><BR>&nbsp;&nbsp;&nbsp;&nbsp;
'Get a random advertisement from the text file. <BR>&nbsp;&nbsp;&nbsp;&nbsp;
GetAd = objLoad.GetAdvertisement("MyAdRot.txt") <BR><BR>&nbsp;&nbsp; End
Function <BR>&nbsp; %&gt; </P>
<P>&nbsp; </P></CODE>
<H3>Example 4: Test the Ad Rotator</H3>
<P>To test the application you have built on the Ad Rotator component, you need
an ASP page that calls the function in the Ad Rotator include file you created.
</P>
<P>Copy and paste the following code in your text editor, and save the file as
<B>DisplayAds.asp</B> in the <I>x</I>:\Inetpub\Wwwroot\Tutorial directory. View
the example with your browser by typing
<B>http://localhost/Tutorial/DisplayAds.asp</B> in the address bar. </P><CODE>
<P>&nbsp; &lt;%@ Language=VBScript %&gt; <BR><BR>&nbsp; &lt;html&gt; <BR>&nbsp;
&lt;head&gt; <BR>&nbsp; &lt;title&gt;Display an Advertisement&lt;/title&gt;
<BR>&nbsp; &lt;/head&gt; <BR>&nbsp; &lt;body&gt; <BR><BR>&nbsp; &lt;font
face="MS Gothic"&gt; <BR>&nbsp; &lt;h2&gt;Display an Advertisement&lt;/h2&gt;
<BR><BR>&nbsp; &lt;comment&gt;Include the file you created to get an
advertisement.&lt;/comment&gt; <BR>&nbsp; &lt;!-- #include File =
"AdRotatorLogic.inc" --&gt; <BR><BR>&nbsp; &lt;comment&gt;Call the Function in
the include file.&lt;/comment&gt; <BR>&nbsp; &lt;%=GetAd()%&gt; <BR><BR>&nbsp;
&lt;/font&gt; <BR>&nbsp; &lt;/body&gt; <BR>&nbsp; &lt;/html&gt; </P></CODE>
<P>In the browser, you should see the following: </P>
<P><FONT face="MS Gothic">
<H2>Display an Advertisement</H2>
<IMG SRC="http://www.microsoft.com/windows/images/bnrWinfam.gif" ALT="Microsoft Windows " WIDTH=250 HEIGHT=60 BORDER=1></FONT>
<P>Click the <B>Refresh</B> button in your browser about 20 times to watch the
advertisement change. Click the advertisement to see how AdRotRedirect.asp
redirects you to the advertiser's Web site. Open AdRotLog.txt to see what was
recorded when you clicked on an advertisement. </P>
<P>&nbsp; </P>
<H2><A name=counting>Lesson 2: Counting Page Hits</A></H2>
<P>It may be useful to know how many times someone requests, or <i>hits</i>, your Web
pages. Sites with high traffic may attract more advertising revenue for you.
Some Web sites use this data to charge advertisers a flat fee per hit. Traffic
information also indicates how customers are navigating through your site and
where ads should be placed. And pages that never seem to be hit might indicate that design changes are needed. </P>
<P>The PageCounter component uses an internal object to record Web page hits on
the server. At regular intervals, PageCounter saves all information to a text
file so that no counts are lost due to power loss or system failure. The
PageCounter component uses three methods, as follows: </P>
<UL>
<LI><B>Hits</B>&nbsp;&nbsp;&nbsp;This method displays the number of hits for a Web page. The
default is the calling page.
<LI><B>PageHit</B>&nbsp;&nbsp;&nbsp;This method increments the hit count for the current page. If
you want hits recorded for an ASP page, this method must be called inside that
page.
<LI><B>Reset</B>&nbsp;&nbsp;&nbsp;This method sets the hit count for a page to zero. The default is
the calling page. </LI></UL>
<P>Copy and paste the following code in your text editor, and save the file as
<B>PageCounter.asp</B> in the <I>x</I>:\Inetpub\Wwwroot\Tutorial directory. View
the example with your browser by typing
<B>http://localhost/Tutorial/PageCounter.asp</B> in the address bar. </P><CODE>
<P>&nbsp; &lt;%@ Language=VBScript %&gt; <BR><BR>&nbsp; &lt;html&gt; <BR>&nbsp;
&lt;head&gt; <BR>&nbsp; &lt;title&gt;Page Counter Example&lt;/title&gt;
<BR>&nbsp; &lt;/head&gt; <BR>&nbsp; &lt;body&gt; <BR>&nbsp; &lt;font face="MS
Gothic"&gt; <BR><BR>&nbsp; &lt;H3&gt;Page Counter Example&lt;/H3&gt;
<BR><BR>&nbsp; &lt;p&gt; <BR>&nbsp; &lt;FORM NAME="PageCounter" METHOD="GET"
ACTION="PageCounter.asp"&gt; <BR>&nbsp; &lt;INPUT TYPE="CHECKBOX" NAME="reset"
VALUE="True"&gt;Reset the Counter for this page?&lt;BR&gt; <BR>&nbsp; &lt;INPUT
TYPE="SUBMIT" VALUE="Submit"&gt; <BR>&nbsp; &lt;/FORM&gt; <BR>&nbsp; &lt;/p&gt;
<BR><BR>&nbsp; &lt;% <BR>&nbsp;&nbsp; 'Instantiate the PageCounter object.
<BR>&nbsp;&nbsp; Set MyPageCounter = Server.CreateObject("MSWC.PageCounter")
<BR><BR>&nbsp;&nbsp; 'Increment the counter for this page. <BR>&nbsp;&nbsp;
MyPageCounter.PageHit <BR><BR>&nbsp;&nbsp; If Request.QueryString("reset") =
"True" Then <BR>&nbsp;&nbsp;&nbsp;&nbsp; 'Reset the counter for this page.
<BR>&nbsp;&nbsp;&nbsp;&nbsp; MyPageCounter.Reset("/Tutorial/PageCounter.asp")
<BR>&nbsp;&nbsp; End If <BR>&nbsp; %&gt; <BR><BR>&nbsp; Hits to this page =
&lt;%=MyPageCounter.Hits %&gt;&lt;BR&gt; <BR><BR>&nbsp; &lt;/font&gt; <BR>&nbsp;
&lt;/body&gt; <BR>&nbsp; &lt;/html&gt; </P></CODE>
<P>In the browser, you should see the following: </P>
<P><FONT face="MS Gothic">
<H3>&nbsp; Page Counter Example</H3>
<P>
<FORM method=get name=PageCounter>&nbsp; <INPUT name=reset type=checkbox
value=True>Reset the Counter for this page?<BR>&nbsp; <INPUT type=button value=Submit> </FORM>
<P>&nbsp; Hits to this page = 1<BR></FONT>
<P>Click the <B>Refresh</B> button in your browser or the <B>Submit</B> button
on the page to watch the hit count grow. Check the box if you want to reset the
counter. </P><BR>
<H2><A name=creating>Lesson 3: Creating a Visual Basic COM Object</A></H2>
<P>In this lesson, you use Visual Basic to create a simple COM object, which you
can call from an ASP page. This example requires Visual Basic with the ActiveX
Wizard, and it is not supported on 64-bit platforms until the Visual Basic runtime is
developed for 64-bit platforms. You create a 32-bit COM object that runs on a
64-bit platform, but you must call the 32-bit COM object from a 32-bit
application. Because IIS is a 64-bit application on 64-bit platforms, it cannot
call 32-bit objects. </P>
<P>Suppose you want to create a Web application that needs functionality
VBScript does not have. In this case, you must create a custom procedure that is
called, as needed, from any ASP page in your application.</P>
<P>Normally, this approach is an adequate solution for encapsulating custom
functionality. However, imagine that you are creating a Web application intended
to service thousands of users and that your procedure encapsulates proprietary
functions you do not want other people to see. In this case, encapsulating your
functionality in the form of a COM component is a superior approach. Components
provide better security and performance than scripts because they are compiled
code. Components also allow you to use functionality provided by Visual Basic,
C++, Java, or any of the other COM-compliant languages.</P>
<H3>Create the ActiveX COM Object</H3>
<P>The ActiveX DLL Wizard of Visual Basic is the easiest way to create a COM
component. You can also use Microsoft Visual C++ to create a COM component,
either by using the Active Template Library (ATL) or by writing all the code
yourself. This example uses Visual Basic. </P>
<P>In this lesson, you learn how to create and encapsulate a
Visual Basic function as a component. Visual Basic includes many financial
functions not available to VBScript. This example computes the future value of
an investment based on a fixed interest rate and periodic, fixed payments.</P>
<OL>
<LI>Open Visual Basic. If you don't see a window titled <B>New Project</B>,
choose <B>File</B> and then click <B>New Project</B>.
<LI>Select <B>ActiveX DLL</B>, and click <B>OK</B>.
<LI>A window should open called <B>Project1 - Class1 (Code)</B>. This is where
you enter your code.
<LI>From the <STRONG>Project </STRONG>menu, click <STRONG>Project1
Properties</STRONG>. In the <STRONG>General</STRONG> property sheet, in the
<STRONG>Project Name</STRONG> box, type <B>ASPTut</B>. Your DLL is called
ASPTut.dll. Select the <STRONG>Unattended Execution</STRONG> check box so that the
project runs without user interaction and has no user interface elements. Make
sure the <B>Threading Model</B> is <B>Apartment Threaded</B> so that more than
one user at a time can use the DLL. Click <STRONG>OK</STRONG>.
<LI>In Visual Basic, you define a class to group together methods and
properties. Under the <B>Project - ASPTut</B> window, click the <B>Class1
(Class1)</B> node to list the class properties below. Under <B>Properties -
Class1</B>, click in the text field beside <B>(Name)</B> and change the class
name to <B>Finance</B>. When you call this COM component in an ASP page or
other script, you will reference it with <b>ASPTut.Finance</b>. Click the drop-down box beside <B>Instancing</B>, and select <B>5 - MultiUse</B>.
<LI>Learn about the Visual Basic function you are about to use. <b>FV</b> is
documented on <a href="http://go.microsoft.com/fwlink/?LinkId=1694" target="_blank">MSDN</A>
under the Visual Basic library.
<LI>The window that was previously titled <B>Project1 - Class1 (Code)</B> should
now be titled <B>ASPTut - Finance (Code)</B>. Copy and paste the following
text into that window:<CODE> <BR><BR>Option Explicit<BR><BR>'Declare the
global variables that will be set by the Property functions.<BR>Dim
gAnnualIntRate As Double<BR>Dim gNumPayPeriods As Integer<BR>Dim gPayment As
Double<BR>Dim gPresentSavings As Variant 'Optional<BR>Dim gWhenDue As Variant
'Optional<BR><BR>Public Function CalcFutureValue() As Double<BR><BR>&nbsp;
'The global variables you pass to the FV function are set<BR>&nbsp; 'when user
sets the properties in the ASP page.<BR>&nbsp; 'You could pass variables into
the CalcFutureValue() function<BR>&nbsp; 'if you wanted to avoid using
properties.<BR>&nbsp; 'CalcFutureValue becomes a method in your
component.<BR><BR>&nbsp; Dim IntRatePerPeriod As Double<BR>&nbsp; Dim
FullFutureValue As Double<BR><BR>&nbsp; If (gAnnualIntRate = Null) Or
(gNumPayPeriods = Null) Or (gPayment = Null) Then<BR>&nbsp;&nbsp;&nbsp;
CalcFutureValue = 0<BR>&nbsp; Else<BR>&nbsp;&nbsp;&nbsp; IntRatePerPeriod =
gAnnualIntRate / 100 / 12<BR>&nbsp;&nbsp;&nbsp; FullFutureValue =
FV(IntRatePerPeriod, gNumPayPeriods, gPayment, gPresentSavings,
gWhenDue)<BR>&nbsp;&nbsp;&nbsp; CalcFutureValue = Round(FullFutureValue,
2)<BR>&nbsp; End If<BR><BR>End Function<BR><BR>Public Property Get
AnnualIntRate() As Double<BR>&nbsp; 'Get functions return the value of the
global variables<BR>&nbsp; 'as if they were properties.<BR>&nbsp; 'In your
ASP page, you might say x = oASPTut.Rate.<BR>&nbsp; AnnualIntRate =
gAnnualIntRate<BR>End Property<BR><BR>Public Property Let AnnualIntRate(ByVal
vAnnualIntRate As Double)<BR>&nbsp; 'Let functions set the global variables
when your ASP page<BR>&nbsp; 'makes a call such as oASPTut.Rate = 5.<BR>&nbsp;
gAnnualIntRate = vAnnualIntRate<BR>End Property<BR><BR>Public Property Get
NumPayPeriods() As Integer<BR>&nbsp; NumPayPeriods = gNumPayPeriods<BR>End
Property<BR><BR>Public Property Let NumPayPeriods(ByVal vNumPayPeriods As
Integer)<BR>&nbsp; gNumPayPeriods = vNumPayPeriods<BR>End
Property<BR><BR>Public Property Get Payment() As Double<BR>&nbsp; Payment =
gPayment<BR>End Property<BR><BR>Public Property Let Payment(ByVal vPayment As
Double)<BR>&nbsp; gPayment = -(vPayment)<BR>End Property<BR><BR>Public
Property Get PresentSavings() As Variant<BR>&nbsp; PresentSavings =
gPresentSavings<BR>End Property<BR><BR>Public Property Let
PresentSavings(ByVal vPresentSavings As Variant)<BR>&nbsp; gPresentSavings =
-(vPresentSavings)<BR>End Property<BR><BR>Public Property Get WhenDue() As
Variant<BR>&nbsp; WhenDue = gWhenDue<BR>End Property<BR><BR>Public Property
Let WhenDue(ByVal vWhenDue As Variant)<BR>&nbsp; gWhenDue = vWhenDue<BR>End
Property<BR><BR></CODE>
<LI>All server components require an entry (starting) point. This is the code
that will be called when the object is first instantiated with
<b>Server.CreateObject</b> Your ASPTut component does
not have to do anything special when it is first called. For this reason, you
can provide an empty <b>Sub Main</b> procedure.&nbsp; From the <B>Project</B> menu,
select <B>Add Module</B>. In the <B>Add Module</B> window, under the
<B>New</B> tab, select the <B>Module</B> icon and click <B>Open</B>. In the
<B>Module 1</B> code window, type <B>Sub Main</B> and hit <B>Enter</B>. An
empty sub is created for you. </FONT>
<LI><FONT face=Verdana,Arial,Helvetica>Save your <b>Sub Main</b> module as
<B>Main.bas</B>. Save your class file as <B>Finance.cls</B>. Save your project
as <B>ASPTut.vbp</B>.
<LI>Click <B>File</B>, and click <B>Make ASPTut.dll</B>. This compiles and
registers the ASPTut.dll. After you have called ASPTut.dll from an ASP page,
you cannot make the DLL in Visual Basic until you unload the application in
which the ASP file is running. One way to do this is to use the <a href="iiabuti.htm">IIS snap-in</a>
to open the properties on your default Web site and click the
<B>Unload</B> button. If you want to register your DLL on another Web server,
copy ASPTut.dll to the server, click <B>Start</B>, click <B>Run</B>, and type
<B>cmd</B> into the <B>Open</B> text box. In the same directory as ASPTut.dll,
type <B>regsvr32 ASPTut.dll</B>.
<LI>Exit Visual Basic. </LI></OL>
<H3>Create an ASP Page to Use Your Visual Basic COM Object</H3>
<P>This example ASP page uses a form to read in user data, creates an instance
of your object, and calculates the future value of your savings plan. </P>
<P>Copy and paste the following code in your text editor, and save the file as
<B>CalculateFutureValue.asp</B> in the <I>x</I>:\Inetpub\Wwwroot\Tutorial
directory. View the example with your browser by typing
<B>http://localhost/Tutorial/CalculateFutureValue.asp </B>in the address bar.
</P><CODE>
<P>&nbsp; &lt;%@ Language=VBScript %&gt;<BR><BR>&nbsp; &lt;%<BR>&nbsp;
Response.Expires = 0<BR>&nbsp; Payment = Request.Form("Payment")<BR>&nbsp;
AnnualIntRate = Request.Form("AnnualIntRate")<BR>&nbsp; NumPayPeriods =
Request.Form("NumPayPeriods")<BR>&nbsp; WhenDue =
Request.Form("WhenDue")<BR>&nbsp; PresentSavings =
Request.Form("PresentSavings")<BR>&nbsp; %&gt;<BR><BR>&nbsp;
&lt;HTML&gt;<BR>&nbsp; &lt;HEAD&gt;&lt;TITLE&gt;Future Value
Calculation&lt;/TITLE&gt;&lt;/HEAD&gt;<BR>&nbsp; &lt;BODY&gt;<BR>&nbsp; &lt;FONT
FACE="MS Gothic"&gt;<BR><BR>&nbsp; &lt;H2 align=center&gt;Calculate the Future
Value of a Savings Plan&lt;/H2&gt;&nbsp;<BR><BR>&nbsp; &lt;FORM METHOD=POST
ACTION="calculatefuturevalue.asp"&gt;&nbsp;<BR>&nbsp; &lt;TABLE cellpadding=4
align=center&gt;&nbsp;<BR>&nbsp; &lt;TR&gt;<BR>&nbsp; &lt;TD&gt;How much do you
plan to save each month?&lt;/TD&gt;<BR>&nbsp; &lt;TD&gt;&lt;INPUT TYPE=TEXT
NAME=Payment VALUE=&lt;%=Payment%&gt;&gt; (Required)&lt;/TD&gt;<BR>&nbsp;
&lt;/TR&gt;&lt;TR&gt;<BR>&nbsp; &lt;TD&gt;Enter the annual interest
rate.&lt;/TD&gt;<BR>&nbsp; &lt;TD&gt;&lt;INPUT TYPE=TEXT NAME=AnnualIntRate
VALUE=&lt;%=AnnualIntRate%&gt;&gt; (Required)&lt;/TD&gt;<BR>&nbsp;
&lt;/TR&gt;&lt;TR&gt;&nbsp;<BR>&nbsp; &lt;TD&gt;For how many months will you
save?&lt;/TD&gt;<BR>&nbsp; &lt;TD&gt;&lt;INPUT TYPE=TEXT NAME=NumPayPeriods
VALUE=&lt;%=NumPayPeriods%&gt;&gt; (Required)&lt;/TD&gt;<BR>&nbsp;
&lt;/TR&gt;&lt;TR&gt;&nbsp;<BR>&nbsp; &lt;TD&gt;When do you make payments in the
month? &lt;/TD&gt;<BR>&nbsp; &lt;TD&gt;&lt;INPUT TYPE=RADIO NAME=WhenDue VALUE=1
&lt;%If 1=WhenDue Then Response.Write"CHECKED"%&gt;&gt;Beginning&nbsp;<BR>&nbsp;
&lt;INPUT TYPE=RADIO NAME=WhenDue VALUE=0 &lt;%If 0=WhenDue Then
Response.Write"CHECKED"%&gt;&gt;End &lt;/TD&gt;<BR>&nbsp;
&lt;/TR&gt;&lt;TR&gt;&nbsp;<BR>&nbsp; &lt;TD&gt;How much is in this savings
account now?&lt;/TD&gt;<BR>&nbsp; &lt;TD&gt;&lt;INPUT TYPE=TEXT
NAME=PresentSavings VALUE=&lt;%=PresentSavings%&gt;&gt; &lt;/TD&gt;<BR>&nbsp;
&lt;/TR&gt;<BR>&nbsp; &lt;/TABLE&gt;<BR>&nbsp; &lt;P align=center&gt;&lt;INPUT
TYPE=SUBMIT VALUE=" Calculate Future Value "&gt;<BR>&nbsp;
&lt;/FORM&gt;&nbsp;<BR><BR>&nbsp; &lt;%<BR>&nbsp; If ("" = Payment) Or ("" =
AnnualIntRate) Or ("" = NumPayPeriods) Then<BR><BR>&nbsp;&nbsp;&nbsp;
Response.Write "&lt;H3 align=center&gt;No valid input entered
yet.&lt;/H3&gt;"<BR><BR>&nbsp; ElseIf (IsNumeric(Payment)) And
(IsNumeric(AnnualIntRate)) And (IsNumeric(NumPayPeriods))
Then<BR><BR>&nbsp;&nbsp;&nbsp; Dim FutureValue<BR>&nbsp;&nbsp;&nbsp; Set oASPTut
= Server.CreateObject("ASPTut.Finance")<BR>&nbsp;&nbsp;&nbsp;
oASPTut.AnnualIntRate = CDbl(AnnualIntRate)<BR>&nbsp;&nbsp;&nbsp;
oASPTut.NumPayPeriods = CInt(NumPayPeriods)<BR>&nbsp;&nbsp;&nbsp;
oASPTut.Payment = CDbl(Payment)<BR>&nbsp;&nbsp;&nbsp; If Not "" = PresentSavings
Then oASPTut.PresentSavings = CDbl(PresentSavings)<BR>&nbsp;&nbsp;&nbsp;
oASPTut.WhenDue = WhenDue<BR>&nbsp;&nbsp;&nbsp; FutureValue =
oASPTut.CalcFutureValue<BR>&nbsp;&nbsp;&nbsp; Response.Write "&lt;H3
align=center&gt;Future value = $" &amp; FutureValue &amp;
"&lt;/H3&gt;"<BR><BR>&nbsp; Else<BR><BR>&nbsp;&nbsp;&nbsp; Response.Write
"&lt;H3 align=center&gt;Some of your values are not
numbers.&lt;/H3&gt;"<BR><BR>&nbsp; End If<BR><BR>&nbsp; %&gt;<BR><BR>&nbsp;
&lt;/FONT&gt;&nbsp;<BR>&nbsp; &lt;/BODY&gt;&nbsp;<BR>&nbsp; &lt;/HTML&gt;
</P></CODE>
<P>In the browser, you should see the following: </P>
<P><FONT face="MS Gothic">
<H2 align=center>Calculate the Future Value of a Savings Plan</H2>
<FORM method=post>
<TABLE align=center cellPadding=4>
<TBODY>
<TR>
<TD>How much do you plan to save each month?</TD>
<TD><INPUT name=Payment> (Required)</TD></TR>
<TR>
<TD>Enter the annual interest rate.</TD>
<TD><INPUT name=AnnualIntRate> (Required)</TD></TR>
<TR>
<TD>For how many months will you save?</TD>
<TD><INPUT name=NumPayPeriods> (Required)</TD></TR>
<TR>
<TD>When do you make payments in the month? </TD>
<TD><INPUT name=WhenDue type=radio value=1>Beginning <INPUT CHECKED
name=WhenDue type=radio value=0>End </TD></TR>
<TR>
<TD>How much is in this savings account now?</TD>
<TD><INPUT name=PresentSavings> </TD></TR></TBODY></TABLE>
<P align=center><INPUT type=button value=" Calculate Future Value "> </FORM>
<H3 align=center>No valid input entered yet.</H3></FONT>
<H2><A name=creatingj>Lesson 4: Creating a Java COM Object</A></H2>
<P>In this lesson, you use Microsoft<66> Visual J++<2B> to create a COM object which
does the same thing as the Visual Basic component in Lesson 3. This step requires Visual J++ 6.0
or later. </P>
<H3>Create the Java COM Object</H3>
<OL>
<LI>Open Visual J++. If you don't see a window titled <B>New Project</B>,
click the <B>File</B> menu and click <B>New Project</B>.
<LI>Select <B>Visual J++ Projects</B>, and click the <B>Empty Project</B>
icon. In the <B>Name</B> text box, type <B>ASPTut</B>. Click <B>Open</B>.
<LI>In the <B>Project</B> menu, click <B>Add Class</B>. In the <B>Name</B>
text box, type <B>ASPTut.java</B>. The class name must be the same as the
project name for a Java server component. Click <B>Open</B>.&nbsp; The
following should appear in a text editing window:<BR><BR><CODE>public class
ASPTut<BR>{<BR>}<BR><BR></CODE>
<LI>Copy the following code, and paste it between the brackets {}. Watch
capitalization because Java is case-sensitive. The following is a method in
your component:<BR><BR><CODE>public double CalcFutureValue(<BR>&nbsp; double
dblAnnualIntRate,<BR>&nbsp; double dblNumPayPeriods,<BR>&nbsp; double
dblPayment,<BR>&nbsp; double dblPresentSavings,<BR>&nbsp; boolean
bWhenDue)<BR>{<BR>&nbsp; double dblRet, dblTemp, dblTemp2, dblTemp3,
dblIntRate;<BR><BR>&nbsp; if (dblAnnualIntRate == 0.0)<BR>&nbsp;
{<BR>&nbsp;&nbsp;&nbsp; dblRet = -dblPresentSavings - dblPayment *
dblNumPayPeriods;<BR>&nbsp; }<BR>&nbsp; else<BR>&nbsp; {<BR>&nbsp;&nbsp;&nbsp;
dblIntRate = dblAnnualIntRate / 100 / 12;<BR>&nbsp;&nbsp;&nbsp; dblPayment =
-dblPayment;<BR>&nbsp;&nbsp;&nbsp; dblPresentSavings =
-dblPresentSavings;<BR><BR>&nbsp;&nbsp;&nbsp; dblTemp = (bWhenDue ? 1.0 +
dblIntRate : 1.0);<BR>&nbsp;&nbsp;&nbsp; dblTemp3 = 1.0 +
dblIntRate;<BR>&nbsp;&nbsp;&nbsp; dblTemp2 = Math.pow(dblTemp3,
dblNumPayPeriods);&nbsp;<BR>&nbsp;&nbsp;&nbsp; dblRet = -dblPresentSavings *
dblTemp2 - dblPayment * dblTemp * (dblTemp2 - 1.0) / dblIntRate;<BR>&nbsp;
}<BR><BR>&nbsp; return dblRet;<BR>}</CODE><BR><BR>
<LI>From the <B>Build</B> menu, click <B>Build</B>. Look in the <B>Task
List</B> window below the text editing window to see whether any errors are
generated.
<LI>The Java class file must be registered on the same machine as the Web
server. In a command window, find the ASPTut.class file that was built. It is
most likely either in %USERPROFILE%\My Documents\Visual Studio Projects\ASPTut or in
<I>x</I>:\Documents and Settings\<I>user name</I>\My Documents\Visual Studio
Projects\ASPTut, where x: is the drive on which you installed Windows. Copy
ASPTut.class to <I>x</I>:\Winnt\Java\Trustlib. Type <B>javareg /register
/class:ASPTut /progid:MS.ASPTut.Java</B>, and press <b>ENTER</b> to register the Java
class.
<LI>Close Visual J++. </LI></OL>
<H3>Create an ASP Page to Use Your Java COM Object</H3>
<P>This example ASP page uses a form to read in user data, creates an instance
of your object, and calculates the future value of your savings plan. This
example uses JScript, but you can call a Java component from VBScript as well.
</P>
<P>Copy and paste the following code in your text editor, and save the file as
<B>CalculateFutureValueJava.asp</B> in the <I>x</I>:\Inetpub\wwwroot\Tutorial
directory. View the example with your browser by typing
<B>http://localhost/Tutorial/CalculateFutureValueJava.asp</B> in the address
bar. </P><CODE>&nbsp; </CODE><CODE>&lt;%@ Language=JScript
%&gt;<BR><BR></CODE><CODE>&nbsp; </CODE><CODE>&lt;%<BR></CODE><CODE>&nbsp;
</CODE><CODE>Response.Expires = 0;<BR></CODE><CODE>&nbsp; </CODE><CODE>Payment =
Request.Form("Payment");<BR></CODE><CODE>&nbsp; </CODE><CODE>AnnualIntRate =
Request.Form("AnnualIntRate");<BR></CODE><CODE>&nbsp; </CODE><CODE>NumPayPeriods
= Request.Form("NumPayPeriods");<BR></CODE><CODE>&nbsp; </CODE><CODE>WhenDue =
Request.Form("WhenDue");<BR></CODE><CODE>&nbsp; </CODE><CODE>PresentSavings =
Request.Form("PresentSavings");<BR></CODE><CODE>&nbsp;
</CODE><CODE>%&gt;<BR><BR></CODE><CODE>&nbsp;
</CODE><CODE>&lt;HTML&gt;<BR></CODE><CODE>&nbsp;
</CODE><CODE>&lt;HEAD&gt;&lt;TITLE&gt;Future Value Calculation -
Java&lt;/TITLE&gt;&lt;/HEAD&gt;<BR></CODE><CODE>&nbsp;
</CODE><CODE>&lt;BODY&gt;<BR></CODE><CODE>&nbsp; </CODE><CODE>&lt;FONT FACE="MS
Gothic"&gt;<BR><BR></CODE><CODE>&nbsp; </CODE><CODE>&lt;H2
align=center&gt;Calculate the Future Value of a Savings
Plan&lt;/H2&gt;&nbsp;<BR><BR></CODE><CODE>&nbsp; </CODE><CODE>&lt;FORM
METHOD=POST
ACTION="calculatefuturevaluejava.asp"&gt;&nbsp;<BR></CODE><CODE>&nbsp;
</CODE><CODE>&lt;TABLE cellpadding=4
align=center&gt;&nbsp;<BR></CODE><CODE>&nbsp;
</CODE><CODE>&lt;TR&gt;<BR></CODE><CODE>&nbsp; </CODE><CODE>&lt;TD&gt;How much
do you plan to save each month?&lt;/TD&gt;<BR></CODE><CODE>&nbsp;
</CODE><CODE>&lt;TD&gt;&lt;INPUT TYPE=TEXT NAME=Payment
VALUE=&lt;%=Payment%&gt;&gt; (Required)&lt;/TD&gt;<BR></CODE><CODE>&nbsp;
</CODE><CODE>&lt;/TR&gt;&lt;TR&gt;<BR></CODE><CODE>&nbsp;
</CODE><CODE>&lt;TD&gt;Enter the annual interest
rate.&lt;/TD&gt;<BR></CODE><CODE>&nbsp; </CODE><CODE>&lt;TD&gt;&lt;INPUT
TYPE=TEXT NAME=AnnualIntRate VALUE=&lt;%=AnnualIntRate%&gt;&gt;
(Required)&lt;/TD&gt;<BR></CODE><CODE>&nbsp;
</CODE><CODE>&lt;/TR&gt;&lt;TR&gt;&nbsp;<BR></CODE><CODE>&nbsp;
</CODE><CODE>&lt;TD&gt;For how many months will you
save?&lt;/TD&gt;<BR></CODE><CODE>&nbsp; </CODE><CODE>&lt;TD&gt;&lt;INPUT
TYPE=TEXT NAME=NumPayPeriods VALUE=&lt;%=NumPayPeriods%&gt;&gt;
(Required)&lt;/TD&gt;<BR></CODE><CODE>&nbsp;
</CODE><CODE>&lt;/TR&gt;&lt;TR&gt;&nbsp;<BR></CODE><CODE>&nbsp;
</CODE><CODE>&lt;TD&gt;When do you make payments in the month?
&lt;/TD&gt;<BR></CODE><CODE>&nbsp; </CODE><CODE>&lt;TD&gt;&lt;INPUT TYPE=RADIO
NAME=WhenDue VALUE=1 &lt;%if (1==WhenDue)
Response.Write("CHECKED")%&gt;&gt;Beginning&nbsp;<BR></CODE><CODE>&nbsp;
</CODE><CODE>&lt;INPUT TYPE=RADIO NAME=WhenDue VALUE=0 &lt;%if (0==WhenDue)
Response.Write("CHECKED")%&gt;&gt;End &lt;/TD&gt;<BR></CODE><CODE>&nbsp;
</CODE><CODE>&lt;/TR&gt;&lt;TR&gt;&nbsp;<BR></CODE><CODE>&nbsp;
</CODE><CODE>&lt;TD&gt;How much is in this savings account
now?&lt;/TD&gt;<BR></CODE><CODE>&nbsp; </CODE><CODE>&lt;TD&gt;&lt;INPUT
TYPE=TEXT NAME=PresentSavings VALUE=&lt;%=PresentSavings%&gt;&gt;
&lt;/TD&gt;<BR></CODE><CODE>&nbsp;
</CODE><CODE>&lt;/TR&gt;<BR></CODE><CODE>&nbsp;
</CODE><CODE>&lt;/TABLE&gt;<BR></CODE><CODE>&nbsp; </CODE><CODE>&lt;P
align=center&gt;&lt;INPUT TYPE=SUBMIT VALUE=" Calculate Future Value
"&gt;<BR></CODE><CODE>&nbsp;
</CODE><CODE>&lt;/FORM&gt;&nbsp;<BR><BR></CODE><CODE>&nbsp;
</CODE><CODE>&lt;%<BR><BR></CODE><CODE>&nbsp; </CODE><CODE>if (("" == Payment)
|| ("" == AnnualIntRate) || ("" == NumPayPeriods)) {<BR><BR></CODE><CODE>&nbsp;
&nbsp; </CODE><CODE>Response.Write("&lt;H3 align=center&gt;No valid input
entered yet.&lt;/H3&gt;");<BR><BR></CODE><CODE>&nbsp; </CODE><CODE>} else
{<BR><BR></CODE><CODE>&nbsp; &nbsp; </CODE><CODE>AnnualIntRate =
parseFloat(AnnualIntRate)<BR></CODE><CODE>&nbsp; &nbsp;
</CODE><CODE>NumPayPeriods = parseFloat(NumPayPeriods)<BR></CODE><CODE>&nbsp;
&nbsp; </CODE><CODE>Payment = parseFloat(Payment)<BR></CODE><CODE>&nbsp; &nbsp;
</CODE><CODE>if ("" != PresentSavings) PresentSavings =
parseFloat(PresentSavings);<BR><BR></CODE><CODE>&nbsp; &nbsp; </CODE><CODE>if
((isNaN(Payment)) || (isNaN(AnnualIntRate)) || (isNaN(NumPayPeriods)))
{<BR><BR></CODE><CODE>&nbsp; &nbsp; &nbsp; </CODE><CODE>Response.Write("&lt;H3
align=center&gt;Some of your values are not
numbers.&lt;/H3&gt;");<BR><BR></CODE><CODE>&nbsp; &nbsp; </CODE><CODE>} else
{<BR><BR></CODE><CODE>&nbsp; &nbsp; &nbsp; </CODE><CODE>var FutureValue,
Cents;<BR></CODE><CODE>&nbsp; &nbsp; &nbsp; </CODE><CODE>var oASPTut =
Server.CreateObject("MS.ASPTut.Java");<BR></CODE><CODE>&nbsp; &nbsp; &nbsp;
</CODE><CODE>FutureValue = oASPTut.CalcFutureValue(AnnualIntRate, NumPayPeriods,
Payment, PresentSavings, WhenDue);<BR><BR></CODE><CODE>&nbsp; &nbsp; &nbsp;
</CODE><CODE>Response.Write("&lt;H3 align=center&gt;Future value = $" +
parseInt(FutureValue) + "&lt;/H3&gt;");<BR><BR></CODE><CODE>&nbsp; &nbsp;
</CODE><CODE>}<BR></CODE><CODE>&nbsp; </CODE><CODE>}<BR></CODE><CODE>&nbsp;
</CODE><CODE>%&gt;<BR><BR></CODE><CODE>&nbsp;
</CODE><CODE>&lt;/FONT&gt;&nbsp;<BR></CODE><CODE>&nbsp;
</CODE><CODE>&lt;/BODY&gt;&nbsp;<BR></CODE><CODE>&nbsp;
</CODE><CODE>&lt;/HTML&gt;<BR></CODE>
<P></P>
<P>In the browser, you should see the following content, which should be identical to the display generated using the Visual Basic
component in Lesson 3 of this module: </P>
<P><FONT face="MS Gothic">
<H2 align=center>Calculate the Future Value of a Savings Plan</H2>
<FORM method=post>
<TABLE align=center cellPadding=4>
<TBODY>
<TR>
<TD>How much do you plan to save each month?</TD>
<TD><INPUT name=Payment> (Required)</TD></TR>
<TR>
<TD>Enter the annual interest rate.</TD>
<TD><INPUT name=AnnualIntRate> (Required)</TD></TR>
<TR>
<TD>For how many months will you save?</TD>
<TD><INPUT name=NumPayPeriods> (Required)</TD></TR>
<TR>
<TD>When do you make payments in the month? </TD>
<TD><INPUT name=WhenDue type=radio value=1>Beginning <INPUT CHECKED
name=WhenDue type=radio value=0>End </TD></TR>
<TR>
<TD>How much is in this savings account now?</TD>
<TD><INPUT name=PresentSavings> </TD></TR></TBODY></TABLE>
<P align=center><INPUT type=button value=" Calculate Future Value "> </FORM>
<H3 align=center>No valid input entered yet.</H3></FONT>
<br>
<H2>Up Next: Maintaining Session State in a Web Application</H2>
<HR class=iis SIZE=1>
<P align=center><a href="/iishelp/common/colegal.htm"><EM><EFBFBD> 1997-2001
Microsoft Corporation. All rights reserved.</EM></A></P></FONT></BODY></HTML>