home *** CD-ROM | disk | FTP | other *** search
/ Chip 1999 September / CHIPCD_9_99.iso / software / uaktualnienia / OptionPackPL / iis4_05.cab / iiatmd3.asp < prev    next >
Text File  |  1998-05-05  |  28KB  |  479 lines

  1. <%@ Language=VBScript EnableSessionState=False %>
  2. <%
  3.   
  4.   ComponentPref =  Request.Form("ComponentPref")     
  5.   If ComponentPref  = "" Then ComponentPref = Request.Cookies("ComponentPreference")
  6.  
  7.    Select Case ComponentPref
  8.    Case "VB5"
  9.       VB5Checked = "Checked"
  10.    Case "JavaComp"
  11.       JavaChecked = "Checked"
  12.    Case Else
  13.        VB5Checked = "Checked"       
  14.        ComponentPref = "VB5"
  15.    End Select
  16.  
  17.   Response.Cookies("ComponentPreference") = ComponentPref
  18.   Response.Cookies("ComponentPreference").Path = "/"
  19.  
  20.  
  21. Response.Expires = 0
  22. LessonFile = Request.ServerVariables("SCRIPT_NAME")
  23.  
  24.   ScriptLanguagePreference = Request.Cookies("ScriptLanguagePreference")
  25.  
  26.   If ScriptLanguagePreference = "" Then
  27.     ScriptLanguagePreference = Request.QueryString("ScriptLanguagePreference")
  28.     If ScriptLanguagePreference = "" Then
  29.       Response.Redirect "/iishelp/iis/htm/asp/iiselect.asp?LessonFile=" & Server.URLEncode(LessonFile)
  30.     End If
  31.   End If
  32.  
  33. 'Determine the physical path for the current page and then remove the
  34. 'name of the file from the path (leaving just the directory).
  35. MainPath = Request.ServerVariables("PATH_TRANSLATED")
  36. Length = Len(MainPath)
  37. i = 0
  38. Do Until (i  = 2)
  39.   Do While (Mid(MainPath, Length, 1) <> "\")
  40.     Length = Length - 1      
  41.   Loop  
  42. i = i + 1
  43. MainPath = left(MainPath, (Length-1)) 
  44. Loop
  45. FilePath = left(MainPath, Length) + "\tutorial"
  46.  
  47.  
  48. 'Determine the virtual path for the current page and then remove the
  49. 'name of the file from the path (leaving just the directory).
  50. MainPath = Request.ServerVariables("PATH_INFO")
  51.  
  52. Length = Len(MainPath)
  53. i = 0
  54. Do Until (i  = 2)
  55.   Do While (Mid(MainPath, Length, 1) <> "/")
  56.     Length = Length - 1      
  57.   Loop  
  58. i = i + 1
  59. MainPath = left(MainPath, (Length-1)) 
  60. Loop
  61. VirtFilePath = left(MainPath, Length) + "/tutorial"
  62.  
  63. %>
  64.  
  65. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
  66. <html><head><title>Module 3: Writing Your Own Components</title>
  67.  
  68. <SCRIPT LANGUAGE="JavaScript">
  69.     TempString = navigator.appVersion
  70.     if (navigator.appName == "Microsoft Internet Explorer"){    
  71. // Check to see if browser is Microsoft
  72.         if (TempString.indexOf ("4.") >= 0){
  73. // Check to see if it is IE 4
  74.             document.writeln('<link rel="stylesheet" type="text/css" href="/iishelp/common/coua.css">');
  75.         }
  76.         else {
  77.             document.writeln('<link rel="stylesheet" type="text/css" href="/iishelp/common/cocss.css">');
  78.         }
  79.     }
  80.     else if (navigator.appName == "Netscape") {                        
  81. // Check to see if browser is Netscape
  82.         document.writeln('<link rel="stylesheet" type="text/css" href="/iishelp/common/coua.css">');
  83.     }
  84.     else
  85.         document.writeln('<link rel="stylesheet" type="text/css" href="/iishelp/common/cocss.css">');
  86. </script> 
  87.  
  88. <META NAME="ROBOTS" CONTENT="NOINDEX"></head>
  89.  
  90. <body bgcolor="#FFFFFF" text="#000000"><font face="Verdana,Arial,Helvetica">
  91.  
  92. <h1><a name="module3writingyourownactivexservercomponents">Module 3: Writing Your Own Components</a></h1>
  93.  
  94. <p><a href="iiselect.asp?LessonFile=<%= Server.URLEncode(LessonFile)%>"><strong>Choose a scripting language for this lesson.</strong></a></p>
  95.  
  96. <p>In <a href="iiatmd2.asp">Module 2</a> you familiarized yourself with the components Active Server Pages (ASP) provides, now it's time to think about creating your own components, components that meet your specific needs.</p>
  97.  
  98. <p>Suppose you want create an ASP application that provides users with access to specific financial functions through your Web site. ASP does not explicitly provide such functionality, but getting it is as easy as creating your own Java or ActiveX component, which you will do in this module.</p>
  99.  
  100. <p>To get started, use the following form to select a component that you would like to learn how to create and implement:</p>
  101.  
  102. <hr>
  103.  
  104. <h3><A NAME="H3_22047542">Select a component to create for this lesson:</A></h3>
  105.  
  106. <form method=post action="iiatmd3.asp#location">
  107. <input type=radio name=ComponentPref value=VB5 <%= VB5Checked  %>>Visual Basic 5.0 ActiveX Component<br>
  108. <input type=radio name=ComponentPref value=JavaComp <%= JavaChecked %>>Visual J++ 1.1 Java™ Component<br><br>
  109. <input type=submit value="Select">
  110. </form>
  111.  
  112. <hr>
  113.  
  114. <p><strong><span style="color: #0000FF"><font color="#0000FF"><a name="location">Important</a></font></span></strong>   </p>
  115.  
  116. <ol>
  117. <li>To save and view your work in this module, you require the following: 
  118.  
  119. <ul>
  120. <li>Write and Script Web server permissions for the <%= VirtFilePath %> virtual directory on the <%= Request.ServerVariables("SERVER_NAME")%> Web server (with Active Server Pages installed).  For more information, see <a href="/iishelp/iis/htm/core/iiwspsc.htm">Setting Web Server Permissions</a>.</li>
  121.  
  122.  
  123. <li>Your Windows NT account must have Windows NT File System (NTFS) permissions that enable you to read, write, and run programs in the 
  124.  
  125. <%
  126.   If ComponentPref = "JavaComp" Then
  127. %> <em>DriveLetter</em>:\Winnt\Java directory and its subdirectories, where <em>DriveLetter</em> is the letter mapped to the appropriate drive of the <%= Request.ServerVariables("SERVER_NAME")%> Web server.</li>
  128. <%Else%><em>DriveLetter</em>:\Winnt\System32\Inetsrv\ where you replace <em>DriveLetter</em> with the letter mapped to the appropriate drive of the <%= Request.ServerVariables("SERVER_NAME")%> Web server. (If you did not accept the default installation directory, substitute the name of your installation directory  for \Winnt\System32.)</li>
  129. <% End If %>
  130.  
  131. </ul>
  132.  
  133. <li>To complete this module, on the <%= Request.ServerVariables("SERVER_NAME") %> Web server you must have installed: </li>
  134.  
  135. <ul>
  136.  <li><% If ComponentPref = "JavaComp" Then
  137. %>Microsoft®  Visual J++™ 1.1.
  138. <%Else%>Either the 32-bit version of Microsoft® Visual Basic 5.0 Professional Edition or Visual Basic 5.0 Enterprise Edition development system.
  139. <% End If %></li>
  140. </ul>
  141.  
  142. <li>If you have disabled your Web browser's ability to run Java programs, enable this feature  before proceeding with the tutorial.
  143.  
  144. </ol>
  145.  
  146. <hr>
  147.  
  148. <h2><a name="creatingthefinancecomponent">Lesson 1: Creating the <%
  149.   If ComponentPref = "JavaComp" Then
  150. %>Java
  151. <%Else%>ActiveX
  152. <% End If %> Finance Component</a></h2>
  153.  
  154.  
  155.  
  156. <%  If ComponentPref = "JavaComp" Then%>
  157.  
  158.  
  159. <p>A component should contain a set of related methods (functions) that provide added value beyond what is in the scripting language that will be calling it. Because <%= ScriptLanguagePreference %> does not provide financial functions, you must explicitly create a finance function. Specifically, for this tutorial you will learn how to create a function that computes the future value of an investment, which returns an annuity based on a fixed interest rate and periodic, fixed payments.</p>
  160.  
  161. <h3><A NAME="H3_22050303">Start Visual J++</A></h3>
  162.  
  163. <ol>
  164. <li>Click <strong>Start</strong>, point to <strong>Programs</strong>, then point to <strong>Microsoft Visual J++ 1.1</strong></li>
  165. <li>Click <strong>Microsoft Developer Studio</strong> in the submenu to run the design environment. </li>
  166. </ol>
  167.  
  168. <h3><a name="nametheproject">Start and Name a Project</a></h3>
  169.  
  170. <ol>
  171. <li>Click <strong>File</strong>.</li>
  172. <li>Select <strong>New</strong>.</li>
  173. <li>Click the <strong>Project</strong> tab.</li>
  174. <li>Select <strong>Java Project</strong>.</li>
  175. <li>In the <strong>Project Name</strong> box, type Finance, then click <strong>OK</strong>. </li>
  176. </ol>
  177.  
  178. <h3><A NAME="H3_22050969">Add the Finance Class to the Project</A></h3>
  179.  
  180. <ol>
  181. <li>In the <strong>Insert</strong> menu, choose <strong>New Class</strong>.</li>
  182. <li>In the <strong>Name</strong> box, type Finance, then click <strong>OK</strong>.   The following should appear in the text editor:</li>
  183.  
  184. <pre><font size="3" face="courier">class Finance {
  185.  
  186.  
  187. }
  188. </pre></font>
  189.  
  190. <p><strong>Note</strong>   The Class name must be the same as the Project name for a Java server component.</p>
  191. </ol>
  192.  
  193. <h3><A NAME="H3_22051481">Add the CalcFV Function to the Finance Class</A></h3>
  194.  
  195. <ol>    
  196. <li>Select the <strong>ClassView</strong> tab (selected by default).</li>
  197. <li>Expand the <strong>Finance Classes</strong> item in the tree control.</li>
  198. <li>Right-click <strong>Finance</strong> class and select <strong>Add Method</strong>.</li>
  199. <li>In the <strong>Return Type</strong> box, type <strong>public double</strong>.</li>
  200. <li>In the <strong>Method declaration</strong> box, copy and paste the following: </li>
  201.  
  202. <pre><font size="3" face="courier">CalcFV(double dblRate, double dblNPer, double dblPMT, double dblPv, boolean bType)</pre></font>  
  203.  
  204. <p>With this declaration, you define the a finance function, belonging to the Finance class, that computes the future value of an investment. <!--</p>--><br>
  205.  
  206. <li>Click <strong>OK</strong>.  The following appears in the Visual J++ text editor:</li>
  207.  
  208. <pre><font size="3" face="courier">class Finance {
  209.     public double CalcFV(double dblRate, 
  210.                double dblNPer, 
  211.                double dblPMT, 
  212.                double dblPv, 
  213.                boolean bType) {     
  214.  
  215.  
  216.     }
  217.     }
  218. </pre></font>
  219.  
  220. <li>Within the innermost set of brackets, copy and paste the following Java code into the text editor:</li>
  221.  
  222. <pre><font size="3" face="courier">  double    dblRet, dblTemp, dblTemp2, dblTemp3;
  223.  
  224.         if (dblRate == 0.0) {
  225.             dblRet = -dblPv - dblPMT * dblNPer;
  226.         } else {
  227.             dblTemp = (bType ? 1.0 + dblRate : 1.0);
  228.             dblTemp3 = 1.0 + dblRate;
  229.             dblTemp2 = Math.pow(dblTemp3, dblNPer);  
  230.             dblRet = -dblPv * dblTemp2 - dblPMT * dblTemp * (dblTemp2 - 1.0) / dblRate;
  231.            }
  232.  
  233.         return dblRet;
  234. </pre></font>
  235.  
  236. <p>Don't be intimidated by this code, it simply defines the mathematical equation (in Java's syntax) necessary for computing the future value of an investment.  If you are interested, you can find information about this commonly used equation in almost any financial mathematics or accounting text book.<!--</p>--><br>
  237.  
  238. <p><strong>Note</strong>   Java is case sensitive, so if you decide to type the previous lines of code into the text editor, be sure to type Java syntax and variables exactly as shown.<!--</p>--><br>
  239.     
  240. </ol>
  241.  
  242. <h3><A NAME="H3_22053702">Build the Finance Component</A></h3>
  243.  
  244. <ol>
  245. <li>In the <strong>Build</strong> menu, Select <strong>Build Finance</strong>. </li>
  246. <li>In the <strong>Build</strong> window (located below the <strong>ClassView</strong> and text editing windows) make sure the build process has not generated any errors or warnings.</li>
  247. </ol>
  248.  
  249. <h3><A NAME="H3_22054061">Copy the Finance Component to the Trustlib directory</A></h3>
  250.  
  251. <ol>
  252. <li>Click the Windows <strong>Start</strong> button, point to <strong>Programs</strong>, then click <strong>Windows Explorer</strong>.</li>
  253. <li>Copy the Finance.class component from the Program Files\DevStudio\MyProjects\Finance\ directory to the <%= Request.ServerVariables("SERVER_NAME") %> Web server's Winnt\Java\Trustlib directory.</li>
  254. </ol>
  255.  
  256. <h3><a name="registerthefinanceservercomponent">Register the Finance Java Class</a></h3>
  257.  
  258. <p>You must register the Finance Java class to make it callable by JScript and all of the other OLE-compatible languages on your computer.<!--</p>--><br>
  259.  
  260. <ol>
  261. <li>Open a command-prompt window.</li>
  262. <li>Type <strong>cd <em>Drive Letter</em>:\<%= Request.ServerVariables("SERVER_NAME")%>\Program Files\DevStudio\VJ\Bin\</strong> at the command prompt, where <em>DriveLetter</em> is the letter mapped to the appropriate drive on your computer. (If you did not accept the default installation directory, substitute the name of your installation directory  for \Program Files\DevStudio\VJ\Bin\.)</li>
  263. <li>Press the <strong>Enter</strong> key. </li>
  264. <li>Type <strong>javareg /register /class:Finance /progid:MS.Finance.Java</strong>. </li>
  265. <li>Press the <strong>Enter</strong> key. </li>
  266. <li>Click the <strong>OK</strong> button when a dialog box appears that says <strong>Successfully Registered Java class "Finance" as CLSID</strong>. </li>
  267. <li>Close the command-prompt window.</li>
  268. </ol>
  269.  
  270. <%Else%>
  271. <p>A component should contain a set of related methods (functions) that provide added value beyond what is in the scripting language that will be calling it. Because <%= ScriptLanguagePreference %> does not provide financial functions, you must give access to the Visual Basic finance functions through your Finance server component. This server component could expose all of the Visual Basic finance functions including the <strong>DDB</strong> function (double-declining balance), <strong>FV</strong> function (future value), <strong>IPmt</strong> function (interest payment), <strong>IRR</strong> function (internal rate of return), and others. However, for this tutorial you will only the implement the <strong>FV</strong> function, which returns an annuity based on a fixed interest rate and periodic, fixed payments. <!--</p>--><br>
  272.  
  273. <h3><a name="startvisualbasic">Start Visual Basic</a></h3>
  274.  
  275. <ol>
  276. <li>Click <strong>Start</strong>, point to <strong>Programs</strong>, then point to <strong>Microsoft Visual Basic 5.0</strong></li>
  277. <li>Click <strong>Visual Basic 5.0</strong> in the submenu to run the design environment. </li>
  278. </ol>
  279.  
  280. <h3><a name="nametheproject">Start and Name a Project</a></h3>
  281.  
  282. <ol>
  283. <li>In the <strong>New Project</strong> dialog box, double-click <strong>ActiveX DLL</strong>.</li>
  284. <li>On the <strong>Project </strong> menu, click <strong>Project1 Properties</strong>. </li>
  285. <li>On the <strong>General</strong> property sheet, in the <strong>Project Name</strong> box, type MS. </li>
  286. <li>Select <strong>Unattended Execution</strong>. </li>
  287.  
  288. <p><strong>Note</strong>   Selecting this option indicates that the project is intended to run without user interaction and should have no user interface elements.<!--</p>--><br>
  289.  
  290. <li>Click <strong>OK</strong>.</li>
  291. </ol>
  292.  
  293. <p>The project is now named MS. Later, you will reference the Finance server component as <font face="courier" size="3"><code>MS.Finance</font></code> from an ASP script. <!--</p>--><br>
  294.  
  295. <h3><a name="addthefinanceclasstotheproject">Add the Finance Class to the Project</a></h3>
  296.  
  297. <p>In Visual Basic, to create a component with a set of functionality you can call, you define a <em>class</em>. A class groups methods and properties.  In your project, it will be the place within which you specify your finance methods.<!--</p>--><br>
  298.  
  299. <ol>
  300. <li>Press F4 to open the <strong>Properties</strong> window for the class module, then double-click the <strong>Name</strong> property and type <strong>Function</strong>, then press ENTER.</li>
  301. <li>Double-click <strong>Instancing</strong>. </li>
  302. <li>Click the arrow, then select <strong>5 - MultiUse</strong>. </li>
  303. </ol>
  304.  
  305. <h3><a name="learnmoreaboutvisualbasicfinancefunctions">Learn More About Visual Basic Finance Functions</a></h3>
  306.  
  307. <p>The Visual Basic Help system describes available financial functions.<!--</p>--><br>
  308.  
  309. <ol>
  310. <li>Click <strong>Help</strong>. </li>
  311. <li>Select <strong>Microsoft Visual Basic Help Topics</strong>.</li>
  312. <li>Select the <strong>Index</strong> tab, then type <strong>financial functions</strong> as the word to look for.</li>
  313. <li>Double-click the <strong>financial functions</strong> index entry. </li>
  314. <li>Click <strong>FV Function</strong> to learn more about it.</li>
  315. <li>Close the <strong>Visual Basic Help</strong> dialog box when you have finished reviewing the finance functions.</li>
  316. </ol>
  317.  
  318. <h3><a name="addthecalcfvfunctiontothefinanceclass">Add the CalcFV Function to the Finance Class</a></h3>
  319.  
  320. <p>The Finance server component does require some programming code. This code will make the Visual Basic built-in future value function available to languages making use of your component. <!--</p>--><br>
  321.  
  322. <p>Copy and paste the following lines into the Finance class code window:<!--</p>--><br>
  323.  
  324. <pre><font face="courier" size="3">Public Function CalcFV(rate, nper, pmt, Optional pv, Optional whendue) 
  325. CalcFV = FV(rate, nper, pmt, pv, whendue)
  326. End Function</font></pre>
  327.  
  328. <h3><a name="addthecomponentsentrypoint">Add the Component’s Entry Point</a></h3>
  329.  
  330. <p>All server components require an entry (starting) point. This is the code that will be called when the object is first made available to a language. In VBScript, when you use <strong>Server.CreateObject</strong>, an instance is created of an object. When the <strong>Server.CreateObject </strong>statement is executed, the <strong>Sub Main</strong> procedure in a server component (that is, one created with Visual Basic) is called.</p>
  331.  
  332. <p>Your finance component does not have to do anything special to initialize itself when it is called. For that reason, you can provide an empty (no Visual Basic statements) <strong>Sub</strong> <strong>Main</strong> procedure. <!--</p>--><br>
  333.  
  334. <ol>
  335. <li>In the <strong>Project </strong>menu, select <strong>Add Module</strong>.</li>
  336. <li>In the <strong>Module 1</strong>dialog box, double-click the module icon.</li>
  337. <li>In the Module 1 code window, type <strong>Sub Main</strong>.</li>
  338. <li>Press Enter.</li>
  339. </ol>
  340.  
  341. <p>This automatically enters the following code:<!--</p>--><br>
  342.  
  343. <pre><font face="courier" size="3">Sub Main()
  344. End Sub</font></pre> 
  345.  
  346. <h3><a name="savethefinanceproject">Save the Finance Project</a></h3>
  347.  
  348. <p>When you save your work, you will be asked to save all three parts of the Visual Basic project. These include the project file, the class 
  349. module, and the code module.<!--</p>--><br>
  350.  
  351. <ol>
  352. <li>Open the <strong>File </strong>menu.</li>
  353. <li>Select <strong>Save Project</strong>.</li>
  354. <li>In the <strong>File name</strong> text box, type Finance.  Select the following path on the <%= Request.ServerVariables("SERVER_NAME")%> Web server: <strong><em>DriveLetter</em>:\Winnt\System32\Inetsrv\</strong> where <em>DriveLetter</em> is the letter mapped to the appropriate drive. (If you did not accept the default installation directory, substitute the name of your installation directory  for \Winnt\System32.)</li>
  355. <li>Click the <strong>Save</strong> button.</li>
  356. <p>If a previous user has completed this portion of the tutorial, a message will appear stating that the file already exists. Save your version of the file in place of the older version.<!--</p>--><br>
  357. <li>Double-click the value <strong>Project1</strong> in the <strong>File name</strong> text box to select it.</li>
  358. <li>Type the name <strong>Finance</strong> for the Project file (.vbp).</li>
  359. <li>Click the <strong>Save</strong> button to save the project.</li>
  360. <p>If a previous user has completed this portion of the tutorial, a message will appear stating that the file already exists. Save your version of the file in place of the older version.<!--</p>--><br>
  361. </ol>
  362.  
  363. <h3><a name="makethecomponentaninprocesscomponent">Make the Component an In-Process Component</a></h3>
  364.  
  365. <p>Visual Basic allows you to create in-process ActiveX components (formerly called OLE Automation Servers) and out-of-process ActiveX components. An <em>in-process</em> ActiveX component is a dynamic-link library (file name extension .dll) that is loaded by the calling process. An <em>out-of-process</em> ActiveX component is an executable (file name extension .exe) that runs as a separate process from the calling application. Because in-process components are in the same process space as the calling program, they provide better performance than out-of-process components.</p>
  366.  
  367. <p>To make the Finance server component an in-process ActiveX component</p>
  368.  
  369. <ol>
  370. <li>Open the <strong>File</strong> menu.</li>
  371. <li>Select <strong>Make Finance.dll</strong>. </li>
  372. <li>Click the <strong>Options</strong> button. </li>
  373. <li>Select the <strong>Auto Increment</strong> check box. </li>
  374. <li>Click <strong>OK</strong>. </li>
  375. <li>Type <strong><em>DriveLetter</em>:\<%= Request.ServerVariables("SERVER_NAME")%>\Winnt\System32\Inetsrv\Finance</strong> where <em>DriveLetter</em> is the letter mapped to the appropriate drive on your computer. (If you did not accept the default installation directory, substitute the name of your installation directory  for \Winnt\System32.)<br>
  376. If a previous user has completed this portion of the tutorial, a message will appear stating that the file already exists. Save your version of the file in place of the older version.</li>
  377. <li>Exit Visual Basic.</li>
  378. </ol>
  379.  
  380. <h3><a name="registerthefinanceservercomponent">Register the Finance Server Component</a></h3>
  381.  
  382. <p>All server components must be registered. Windows NT and Windows 95 make use of the system registry to keep track of what server 
  383. components are available for use. By registering the Finance server component, you make it callable by VBScript and all of the other 
  384. OLE-compatible languages on your computer.</p>
  385.  
  386. <ol>
  387. <li>Open a command-prompt window.</li>
  388. <li>Type <strong>cd <em>Drive Letter</em>:\<%= Request.ServerVariables("SERVER_NAME")%>\Winnt\System32\Inetsrv</strong> at the command prompt, where <em>DriveLetter</em> is the letter mapped to the appropriate drive on your computer. (If you did not accept the default installation directory, substitute the name of your installation directory  for \Winnt\System32.)</li>
  389. <li>Press the <strong>Enter</strong> key. </li>
  390. <li>Type <strong>regsvr32 Finance.dll</strong>. </li>
  391. <li>Press the <strong>Enter</strong> key. </li>
  392. <li>Click the <strong>OK</strong> button when a dialog box appears that says <strong>DllRegisterServer in finance.dll succeeded</strong>. </li>
  393. <li>Close the command-prompt window.</li>
  394. </ol>
  395.  
  396. <hr>
  397.  
  398. <% End If %>
  399.  
  400. <h2> <a name="callingthefinancecomponentfromascript">Lesson 2: Calling the Finance Component from a Script</a></h2>
  401.  
  402. <p>To test the component, you can call the component from Active Server Pages (ASP), Visual Basic, Microsoft® Office products that use Visual Basic for Applications, or any other OLE Automation controller.</p>
  403.  
  404. <p>To call the Finance server component from Active Server Pages by using <%=ScriptLanguagePreference%>, you can use an HTML form as input to calculate the future 
  405. value of a person’s savings plan.</p>
  406.  
  407. <h3><a name="thehtmlform">The HTML Form</a></h3>
  408.  
  409. <p>An HTML form will be used to gather values that describe a savings plan. These values are assigned variables that are made available to an 
  410. ASP script as part of the <strong>Request</strong> object. You can reference a value from an HTML form. For example, the annual percentage 
  411. rate entered on a form can be referenced by a script using <font face="courier" size="3"><strong><code>Request("APR")</code></strong></font>. The HTML tag <font face="courier" size="3"><code><INPUT TYPE=TEXT NAME=APR></font></code> provides 
  412. the input field necessary to enter a value.</p>
  413.  
  414. <p>To send the form to a Microsoft Web server running ASP, the user presses a Submit button. The Submit button calls the page indicated by the <font face="courier" size="3"><code>ACTION</font></code> property of the HTML form tag. The HTML tag for the Submit button (<font face="courier" size="3"><code><INPUT 
  415. TYPE=SUBMIT VALUE=" Calculate Future Value "></font></code>) uses the value for <font face="courier" size="3"><code>ACTION</font></code> from the HTML form tag (<font face="courier" size="3"><code><FORM METHOD=POST 
  416. ACTION="Finance<%If ScriptLanguagePreference = "JScript" Then
  417. %>j<%Else%><% End If %>.asp"></font></code>) to call the ASP page Finance<%
  418.   If ScriptLanguagePreference = "JScript" Then
  419. %>j<%Else%><% End If %>.asp.</p>
  420. <p>We have created the form for you. Use your text editor to open the file FVform.asp in the <%= Request.ServerVariables("SERVER_NAME")%> Web server's Tutorial directory (<%= FilePath %>).</p>
  421.  
  422. <h3><a name="thescript">The Script</a></h3>
  423.  
  424. <p>You use <%=ScriptLanguagePreference%> to call your Finance server component. The script starts by validating the inputs from the HTML form and assigning default values for any values that were not entered on the form. <%
  425.   If ScriptLanguagePreference = "JScript" Then
  426. %>A custom function called <strong>IsNumeric</strong> tests whether or not a numeric (valid) 
  427. value was entered for each of the boxes on the HTML form. <%Else%>The VBScript <strong>IsNumeric</strong> function tests whether or not a numeric (valid) 
  428. value was entered for each of the boxes on the HTML form.</p>
  429. <% End If %>
  430.  
  431. <%
  432.   If ComponentPref = "JavaComp" Then
  433. %><p><strong>Server.CreateObject</strong> creates an instance of (that is, makes usable) your Finance component named <font face="courier" size="3"><code>MS.Finance.Java</font></code>. After creating an instance 
  434. of the component, you can make use of its methods and properties.  The script line immediately following 
  435. <strong>Server.CreateObject</strong><%Else%>
  436. <p><strong>Server.CreateObject</strong> creates an instance of (that is, makes usable) your Finance component named <font face="courier" size="3"><code>MS.Finance</font></code>. After creating an instance 
  437. of the component, you can make use of its methods and properties.  The script line immediately following 
  438. <strong>Server.CreateObject</strong><% End If %> uses the <strong>CalcFV</strong> method to calculate a savings plan's future value. The result of this calculation appears on the the browser of the user requesting the information.</p>
  439.  
  440. <p>To view the script, use a text editor to open the file <%
  441.   If ScriptLanguagePreference = "JScript" Then
  442. %>Financej.asp
  443.  
  444.  
  445.  
  446. <%Else%>Finance.asp
  447.  
  448.  
  449.  
  450. <% End If %> in the Tutorial directory (<%= FilePath %>).</p>
  451.  
  452. <h3><a name="usingyourbrowsertorunthetest">Using Your Browser to Run the Test</a></h3>
  453.  
  454. <p>To run the <%
  455.   If ScriptLanguagePreference = "JScript" Then
  456. %>Financej.asp
  457. <%Else%>Finance.asp
  458. <% End If %> ASP page, open the  FVform.asp  file, which  renders a form and then calls the <%
  459.   If ScriptLanguagePreference = "JScript" Then
  460. %>Financej.asp<%Else%>Finance.asp<% End If %> script to calculate the future value of the savings plan specified on the form.</p>
  461.  
  462. <ol>
  463. <li>Open FVform.htm by pointing  your browser to <a href="http://<%=Request.ServerVariables("SERVER_NAME")%>/iishelp/iis/htm/tutorial/FVform.asp?ScriptLanguagePreference=<%=ScriptLanguagePreference%>&ComponentPref=<%=ComponentPref%>">http://<%=Request.ServerVariables("SERVER_NAME")%>/iishelp/iis/htm/tutorial/FVform.asp</a>.</li>
  464. <li>Enter values for the form inputs in the <strong>Savings Plan</strong> form. <br></li>
  465. <li>Click the <strong>Calculate Future Value</strong> button. The value of your savings plan should appear. </li>
  466. </ol>
  467.  
  468. <p>In a relatively short time you have created a useful <%
  469.   If ComponentPref = "JavaComp" Then
  470. %>Java<%Else%>ActiveX server<% End If %> component. If you need access to other financial functions, you can implement other financial functions <%
  471.   If ComponentPref = "JavaComp" Then
  472. %>with Visual J++<%Else%>built into Visual Basic<% End If %> as additional methods of your Finance server component. We encourage you to experiment and come up with creative ways to utilize your own <%If ComponentPref = "JavaComp" Then%>Java<%Else%>ActiveX<% End If %> components.  Soon, you will find that there is virtually no limit to the Web applications you can develop using components.</p>
  473.  
  474. <hr class="iis" size="1">
  475. <p align=center><a href="../../../common/colegal.htm"><em>© 1998 Microsoft Corporation. All rights reserved.</em></a></p>
  476. </font>
  477. </body>
  478. </html>
  479.