VB icon

Chat program

Email
Submitted on: 1/6/2015 10:21:00 AM
By: Bhushan- (from psc cd)  
Level: Beginner
User Rating: By 2 Users
Compatibility: ASP (Active Server Pages)
Views: 1086
 
     Chat program useing arrays.
 
code:
Can't Copy and Paste this?
Click here for a copy-and-paste friendly version of this code!
				
'**************************************
' Name: Chat program
' Description:Chat program useing arrays.
' By: Bhushan- (from psc cd)
'**************************************

1. //chatpage.asp
<HTML>
<HEAD>
<TITLE> Chat Page </TITLE>
</HEAD>
<FRAMESET ROWS="*,100">
<FRAME SRC="Display.asp">
<FRAME SRC="Message.asp">
</FRAMESET>
</HTML>
name this file as chatpage.asp. here we are dividing the page into 2 frames.
Next open another page and type the following code..
2. // Display.asp
<%
set MyServer=Request.ServerVariables("SERVER_NAME")
set MyPath=Request.ServerVariables("SCRIPT_NAME")
MySelf="HTTP://"&MyServer&MyPath
%>
<HTML>
<HEAD>
<META HTTP-EQUIV="REFRESH" CONTENT="5;<%=MySelf%>">
<TITLE>Display Page</TITLE>
</HEAD>
<BODY>
<P ALIGN=RIGHT><%=NOW%></P>
<%
TempArray=Application("Talk")
FOR i=0 to Application("TPlace")-1
Response.Write("<P>"&Temparray(i))
NEXT
%>
</BODY>
</HTML>
name the page as display.asp. here the message typed by the user is captured in a Application level variable. Then the message is put in an array and is written on to the browser by reading from that array variable.
Next open another page and type the following code ..
3. // Message.asp
<%
IF not Request.Form("message")="" THEN
Application.LOCK
IF Application("TPlace")>4 THEN 
Application("TPlace")=0
END IF
TempArray=Application("Talk")
TempArray(Application("TPlace"))=Request.Form("message")
Application("Talk")=TempArray
Application("TPlace")=Application("TPlace")+1
Application.Unlock
END IF
%>
<HTML>
<HEAD><TITLE> Message Page </TITLE></HEAD>
<BODY BGCOLOR="LIGHTBLUE">
<FORM METHOD="POST" ACTION="message.asp">
<p><INPUT TYPE=text size="50" name="message" >
<INPUT TYPE="SUBMIT" VALUE="SEND">
</p>
</FORM>
</BODY>
</HTML>
In this page we are creating a text field and a submit button. After typing a message if u click on submit button the message is captured in application variable which will be used by the display.asp
Next open notepad and type the following code and save it as global.asa
4. ///global.asa
<SCRIPT LANGUAGE=VBScript RUNAT=Server>
SUB Application_OnStart
Dim TempArray(5)
Application("Talk")=TempArray
Application("TPlace")=0
Application("ActiveUsers") = 0
END SUB
SUB Session_OnStart
' Change Session Timeout to 20 minutes (if you need to)
Session.Timeout = 20
' Set a Session Start Time
' This is only important to assure we start a session
Session ("Start") = Now
' Increase the active visitors count when we start the session
Application.Lock
Application ("ActiveUsers") = Application ("ActiveUsers") + 1
Application.UnLock
END SUB
SUB Session_OnEnd
' Decrease the active visitors count when the session ends.
Application.Lock
Application ("ActiveUsers") = Application ("ActiveUsers") - 1
Application.UnLock
END SUB
</SCRIPT>


Other 18 submission(s) by this author

 


Report Bad Submission
Use this form to tell us if this entry should be deleted (i.e contains no code, is a virus, etc.).
This submission should be removed because:

Your Vote

What do you think of this code (in the Beginner category)?
(The code with your highest vote will win this month's coding contest!)
Excellent  Good  Average  Below Average  Poor (See voting log ...)
 

Other User Comments


 There are no comments on this submission.
 

Add Your Feedback
Your feedback will be posted below and an email sent to the author. Please remember that the author was kind enough to share this with you, so any criticisms must be stated politely, or they will be deleted. (For feedback not related to this particular code, please click here instead.)
 

To post feedback, first please login.