After a period of ASP learning, the following we combine the content learned to build a simple chat room, although very simple, but we can through him to master a chat room to establish the basic process, and can constantly improve its function.
The following are the main steps:
1, add the code inside the Global.asa file. This section of code deals with the Application_OnStart event, in which a 15-element data is defined, and assigns it to a Application object's properties. The contents of the Global.asa file are as follows.
<script language= "VBScript" runat= "Server" >
SUB Application_OnStart
Dim machats (15) ' defines a data with 15 elements.
Application ("Gachats") =machats ' stores the content of the conversation.
Application ("Gicounter") =0 ' stores the number of conversations you have.
End SUB
</SCRIPT>
2, add the code to the aspchat.asp file. Note that this part of the code is added between the two horizontal lines in the home page, which is between two <p align= "center" ><font size=5> a simple chat room </font></p>
<br>
<%
' Process input
If Request.ServerVariables ("request_method") = "POST" Then
' Mark the Speaker
If Len (Request ("txtwho")) >0 Then
Session ("Sswho") =request ("txtwho")
End If
' Blockade of application objects
Application.Lock
' Create a local reference pointer
Mlcounter=application ("Gicounter")
Machats=application ("Gachats")
' If the number of rows written is more than 10, restart the count.
If Mlcoundter>9 Then
Mlcoundter=0
End If
' Increase user input, counter plus 1
Machat (Mlchounter) =session ("sswho") & ":" &request ("txtcents")
Mlcounter=mlcounter+1
' Set the local variable to be valid within the scope of the application.
Application ("Gicounter") =mlcounter
Application ("Gachats") =machat
' Eliminate the blockade of application objects
Application.UnLock
End If
%>
<%
' Write textarea
If Application ("Gicounter") =0 Then
Lstemp=application ("Gachats") (0)
Else
For x=0 to Application ("Gicounter")-1
lstemp=lstemp& "<br>" Application ("Gachats") (x)
Next
End If
Response.white lstemp
%>
3, and finally the content of the txtwho initialization. That is, when the viewer enters his or her own name once, the user does not have to enter it again, in order to distinguish each of the different browsers, where the "session" object is used. Using session ("sswho") Record the name of the visitor. The following code is written directly below the above code into the aspchat.asp.
<form method= "POST" action= "aspchat.asp" name= "frmasp" >
<div align= "Center" ><center><p> Address: <input type= "text" name= "txtcents" size= "></p>"
</center></div><div align= "Center" ><center><p> object: <input type= "Submit" value= "Send Out" Name= "B1" ></p>
</center></div>
</form>
4. Complete. Just put the 2, 3 step code before and after adding the complete HTM file code and then save as aspchat.asp on it, this is a very simple ASP chat room program, we can continue to strengthen its function as the study of the depth!
The above information by the Beach Kid Finishing production, you can reprint its content, but please be sure to indicate its origin, thank you!