inicio mail me! sindicaci;ón

Build a simple chatting room with ASP

Through the Asp study of a phase, we combine the content that has learned to build a the simplest chatting room below, although very simple, but the basic course that everybody can master a chatting room to build through him, and can perfect its function ceaselessly.

Its introduce below main measure:

1, add the code inside Global.asa file. This part code basically handles Application_onStart incident, incident is here medium, defined a data that has 15 elements, the content of the attribute.Global.asa file that endows with it to an Application object is as follows.

It is quotative content below:
> of < SCRIPT LANGUAGE= “VBScript” RUNAT= “Server”
SUB Application_OnStartDim MaChats(15) defines a data that has 15 elements.
The content that memory of Application(”gaChats” )=maChats talks.
Application(”giCounter” )=0 stores already some conversational amount.
END SUB
< / SCRIPT >

2, code is added in AspChat.asp file. Attention, two in wanting to add this part code in the homepage horizontal between, namely between the > of two < Hr in text. The program judges application above all when this homepage, what whether use is “Post” method, because of the window in this exemple submitting a method is “post” . And when average first time applies for this homepage, those who use is “get” method. If use,so is the word of “post” method, explaining is the new application when the person that some is browsed is referring his conversational content, this is about to undertake handling, because have new conversational content again. Otherwise, first time of the person that explain some is browsed applies for this homepage, did not refer what talk, because this needs only,show current conversational content it is OK to come out.

It is quotative content below:
> of Font Size=5 of < of > of < P Align= “center” a simple chatting room < / Font > < / P >
< Br >
< %
Handle an inputIf Request.ServerVariables(”Request_Method” )= “POST” Then
Indicate teller0 Then of > of If Len(Request(”txtWho” ))
Session(”ssWho” )=Request(”txtWho” )End If
Block Application object
Application.Lock
Found this locality to cite pressing with a fingerMlCounter=Application(”giCounter” )MaChats=Application(”gaChats” )
The linage that if write,enters exceeds 10, begin to note number afresh. 9 Then of If MlCoundter >MlCoundter=0End If
Raise the input of the user, tally is added 1MaChat(mlChounter)=Session(”ssWho” )&”:” &Request("txtCents" )MlCounter=mlCounter 1
It is local and variable setting inside applied limits effective.
Applicati “giCounter” )=mlCounter
Application(”gaChats” )=maChat
Remove the block of Application object
Application.UnlockEnd If
% >
< %
Write TextAreaIf Application(”giCounter” )=0 ThenLstemp=Application(”gaChats” )(0)ElseFor X=0 To Application(”giCounter” )-1Lstemp=lstemp&”" Application(”gaChats” )(x of < Br > )NextEnd If
Response.white Lstemp
% >
< Hr >

3, finally the content initialization TxtWho. The person that should browse namely had inputted his full name later, to distinguish every different person that browse, used “Session” target here. Use the full name of the person that account of Session(”ssWho” ) is browsed. The code below writes in above code directly below in stocking AspChat.asp.

It is quotative content below:
> of < Form Method= “POST” Action= “aspchat.asp” Name= “frmAsp”
> of P of < of Center > of < of > of < Div Align= “center” makes a speech: < of > of 糹 Nput Type= “text” Name= “txtCents” Size= “34″ / P >
< / Center > < / object of > of P of < of Center > of < of > of Div Align= “center” of Div > < : 糹 Nput Type= “submit” Value= ” sends > of ” Name= “B1″ < / P >
< / Center > < / Div >
< / Form >

4. is finished. As long as 2, the code around of 3 paces joins whole Htm file code to be put next it is OK to be Aspchat.asp, this is a very simple Asp chatting chamber program, everybody can strengthen its function ceaselessly as the development of study!

Bookmark:Digg Del.icio.us Reddit

Leave a Comment