ASP files usually contain regular HTML tags and VBScript programming commands. You place the programming commands within <% and %> brackets. ASP scripts work only on Web servers running IIS or machines running Peer Web Services (PWS) 3.0.
When a browser asks an IIS system to deliver a Web page with an HTML or HTM extension, the IIS system simply retrieves the file and transfers the file to the browser. In this case, the IIS system is nothing more than a file server.
In contrast, when a browser requests a file with an ASP extension, the IIS system checks the ASP file closely, finds the VBScript commands in the HTML code, and executes the VBScript commands. Running those commands usually modifies the HTML on the Web page; the resulting HTML is what the browser receives. IIS doesn't send the VBScript code (thus preventing people from easily figuring out how you set up your site), just the HTML that results from a combination of the original HTML and the text that added when the VBScript commands ran.
For example, consider the following one-line ASP file:
<p>The time is <%=time()%> </p>
Before transmitting this file, IIS sees the command =time(), which tells IIS to run the built-in VBScript time function (i.e., the function that returns the current time) and insert the result into the HTML. The resulting HTML that the user sees is
<p>The time is 03:16:32</p>
The ASP file for my solution has a large portion of VBScript at the beginning and a small amount of HTML at the end. The main job of the resulting Web page is to add the collected form text to feedback.txt, but the page also displays the name and email address that the user entered.
The first two statements in the ASP file tell IIS that the script is VBScript (other languages also work in ASP scripts) and that variables must be declared before they are used in the script. In general, you don't need to declare variables in VBScript. However, many people like to declare variables for organizational purposes and to decrease the probability of a mistyped variable name causing a bug. The Option Explicit statement tells IIS to enforce variable declaration.
The two Set statements let you manipulate files on the server. The first Set statement creates a file-system object, which activates the programming language's tools that allow file reads and writes. The second Set statement's parameters provide the name of the file you're working with (the default path is the \winnt\system32 directory), signal that you want to append data to the file (1 signifies read; 8 signifies append), and specify that the data must be in ASCII rather than Unicode. (For the append process to work, the file that you're appending must exist. Create an empty feedback.txt file before you try to execute the OpenTextFile method.)
The uname and email variables receive the user's name and email address. Request.form is a built-in VBScript method. To retrieve the user's information, you must pass the form's field names, "Username" and "UserEmail". You need to surround the form's field names (which must exactly match the names in the input type= statements in the HTML file) with double quotes.
The myfile.writeline method writes a string of characters to a file. In this case, the method writes the user's name and email address (separated by a space) to feedback.txt and starts a new line.
The myfile.close method closes the file. Finally, the last Set statement supports cleanup on the ASP server.
Use As You See Fit
I used this method because I've had trouble with FrontPage's server extensions and because I'm familiar with VB. However, my method might not work for you. VBScript isn't particularly fast, so you might not want to use it for a busy Web site. (My Software Conspiracy Web site has only about 10 visitors a day, so server performance wasn't a consideration.)
Although my example saves the data in a simple form, you might prefer to collect and save data in a Microsoft SQL Server database. If you're thinking about doing some ASP scripting, see Microsoft's Developer Network Web Workshop Web site (http://www.msdn.microsoft.com/ workshop/c-frame.htm#/workshop/server/default.asp) for links to ASP information. For additional ASP information, see SQL Server Magazine.
Technical Information (for support personnel)
Error Type:
Microsoft VBScript compilation (0x800A0400)
Expected statement
/addtext.asp, line 6
("Scripting.FileSystemObject")
I copied the text from the article verbatim.
I found the article very exciting because I have been trying to learn ASP for the past few weeks. I would really appreciate some clarification on this if possible.
Thank you.........I always read your magazine and learn new tricks all the time.
James R. Gregg February 05, 2000