Use ASP to create a simple chat room

Source: Internet
Author: User
After a phase of asp learning, we will build a simple chat room based on the content we have learned. Although it is very simple, you can use it to master the basic process of creating a chat room, and can constantly improve its functions.
The following describes the main steps:
1. Add Global. the code in the asa file. this part of the code mainly processes the Application_onStart event. In this event, a data with 15 elements is defined and assigned to an Application object attribute. global. the content of the asa file is as follows.
<Script language = "VBScript" RUNAT = "Server">
SUB Application_OnStart
Dim maChats (15) defines a data with 15 elements.
Application ("gaChats") = maChats stores the conversation content.
Application ("giCounter") = 0 stores the number of existing conversations.
END SUB
</SCRIPT>
 
2, in AspChat. add code to the asp file. note that you need to add this part of code between two horizontal lines on the home page, that 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
Indicate the speaker
If len (Request ("txtWho")> 0 then
Session ("ssWho") = Request ("txtWho ")
End if
Block Application objects
Application. Lock
Create a local reference pointer
MlCounter = Application ("giCounter ")
MaChats = Application ("gaChats ")
If the number of rows to be written exceeds 10, start counting again.
If mlCoundter> 9 then
MlCoundter = 0
End if
Increase user input and add 1 to counter
MaChat (mlChounter) = Session ("ssWho") & ":" & Request ("txtCents ")
MlCounter = mlCounter + 1
Set local variables to be valid within the application scope.
Applicati "giCounter") = mlCounter
Application ("gaChats") = maChat
Eliminate Application object blocking
Application. Unlock
End if
%>
<%
Write TextArea
If Application ("giCounter") = 0 then

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.