Author: Gan jiping;
Suppose you want to create a simple message book, you can create a database to store user information. However, if you do not need the powerful functions of the database, using FSO to store information will save you time and money. In addition, some ISPs may restrict database applications on the web.
Suppose you have collected some user information in a form. Here is a simple form htmlCode:
<HTML>
<Body>
<Form action = "formhandler. asp" method = "Post">
<Input type = "text" size = "10" name = "username">
<Input type = "text" size = "10" name = "Homepage">
<Input type = "text" size = "10" name = "email">
</Form>
</Body>
</Html>
Let's look at the code for processing the form in formhandler. asp:
<%
'Get form info
Strname = request. Form ("username ")
Strhomepage = request. Form ("Homepage ")
Stremail = request. Form ("email ")
'Create the FSO object
Set FSO = server. Createobject ("scripting. FileSystemObject ")
So far, nothing is new. It is nothing more than getting the values of form fields and assigning values to variables. An interesting part is shown below:
Path = "C: EMP est.txt"
Forreading = 1, forwriting = 2, forappending = 3
'Open the file
Set file = FSO. opentextfile (path, forappending, true)
'Write the info to the file
File. Write (strname) & vbcrlf
File. Write (strhomepage) & vbcrlf
File. Write (stremail) & vbcrlf
'Close and clean up
File. Close
Set file = nothing
Set FSO = nothing
In retrospect, the opentextfile method returns a textstream object, which is another object in the FSO model. Textstream object reveals the operationCompositionContent method, such as writing, reading, and skipping a row. The VB constant vbcrlf generates a line break.
The value true is defined in the Command Parameter of opentextfile, which tells the system to create a file if the file does not exist. If the file does not exist and the true parameter is not defined, an error occurs.
Now go to the directory c: empand open test.txt. You can see the following information:
User's name
User's home page
User's email
Of course, these words can be replaced by any input in the form.