Tutorials to .com

Tutorials to .com » Asp » Skills » The establishment of a simple chat room. (For study and reference)

The establishment of a simple chat room. (For study and reference)

Print View , by: iSee ,Total views: 15 ,Word Count: 872 ,Date: Wed, 26 Aug 2009 Time: 4:00 PM

Beach Boys

asp After a phase of the study, the following combination that we have learned the contents of the establishment of a simple chat room, although very simple, but we can through him to master a chat room to establish the basic processes, and can continuously improve its functions.

The following describes the main steps:

1, add the Global.asa file inside the code. This is part of the code dealt mainly with Application_onStart event, in this case, define a 15 element data and assign it to an application object's properties. Global.asa file reads as follows.
<SCRIPT LANGUAGE="VBScript" RUNAT="Server">
SUB Application_OnStart
dim maChats (15) 'the definition of a 15 element data.
application ( "gaChats") = maChats' store the contents of the conversation.
Application ( "giCounter") = 0 'Store the number of an existing conversation.
END SUB
</ SCRIPT>


2, in the AspChat.asp file add the code. Note that this part of the code should be added to the home page between the two horizontal lines, that is, in the text between the two <hr>. Procedures to determine the first application for the site home page whether using a "Post" method, because in this case the submission of the window is "post". The general application for the site home page for the first time, using a "get" method. So, if we adopt the "post" method If, on the note was a visitor to submit their remarks at the time of re-apply, it is necessary to deal with, because there are new contents of the conversation. Otherwise, the description of a visit by the first application of this home page, there is no to submit any conversation, so just take the current contents of the conversation is displayed on it.
<p align="center"> <font size=5> a simple chat room </ font> </ p>
<br>
"%
'Handling of imported
if Request.ServerVariables ( "Request_Method") = "POST" then
'Indicate the speaker
if len (Request ( "txtWho"))> 0 then
Session ( "ssWho") = Request ( "txtWho")
end if
'Application objects blocking
Application.Lock
'Create a local reference pointer
mlCounter = Application ( "giCounter")
maChats = Application ( "gaChats")
'If the number of rows written more than 10, then re-start counting.
if mlCoundter> 9 then
mlCoundter = 0
end if
'To increase the user's input, the counter plus 1
maChat (mlChounter) = Session ( "ssWho ")&":"& Request (" txtCents ")
mlCounter = mlCounter +1
'The local variable is valid in the range of applications.
Application ( "giCounter") = mlCounter
Application ( "gaChats") = maChat
'Application objects blocking the elimination
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
% "
<hr>

3, the final contents of the txtWho initialization. That is, when visitors enter their name once, do not need to re-enter later, and in order to distinguish each different browsers, where the use of the "Session" object. The use of Session ( "ssWho") recorded the names of visitors. The following code is written directly on the code above into AspChat.asp in the following.
<form method="POST" action="aspchat.asp" name="frmAsp">
<div align="center"> <center> <p> statement: <input type="text" name="txtCents" size="34"> </ p>
</ center> </ div> <div align="center"> <center> <p> object: <input type="submit" value="" name="B1"> </ p>
</ center> </ div>
</ form>

4. Completed. As long as the code before and after adding 2,3 Step full htm file and then the code can be saved as aspchat.asp, which is a very simple asp chat room program, we can learn from the in-depth with the continuous strengthening of its function!

The above information is from the Beach Boys organize production, you may be reproduced and its contents, but please be sure to indicate its source, thank you!


ASP skills Articles


Can't Find What You're Looking For?


Rating: Not yet rated

Comments

No comments posted.