admin
06-10-2003, 04:13 PM
Part 2
In this section we will look at display.asp and the message.asp files. Let's leave out the display.asp for some time and concentrate at the message.asp file.
The message.asp file allows the user to input messages so that that he can chat with others. Now let's see how this is done. Firstly we need to again declare a variable so that the messages can be stored somewhere before it is sent to the text lines. This is done like before.
<%
Dim message
%>
Secondly, we need to create a html form as a medium for the user to enter his messages and chat. So let's do that now.
<HTML>
<HEAD>
<TITLE>Kumar's Online Chat Message Dialogue</TITLE>
</HEAD>
<BODY BGCOLOR="CC99FF">
<CENTER>
<FORM METHOD="POST" ACTION="message.asp">
<FONT SIZE=2>Enter your message in the text box below and click Send Message to Chat.</FONT>
<TABLE BORDER=0 CELLSPACING=0>
<TR>
<TD>INPUT NAME="message" TYPE="TEXT" SIZE=30></TD>
<TD><INPUT TYPE="Submit" Value="Send Message"></TD>
<TD> </TD>
<TD VALIGN=TOP><A HREF="logoff.asp" TARGET="_top"><IMG SRC="logoff.jpg" BORDER="NO"></A></TD>
</TABLE>
</FORM>
</CENTER>
<BODY>
</HTML>
As you can see above a form is created that posts messages to this same file message.asp. This means that after the user enters his message and submits it. It is sent to this same file. Then a verification check is done to check whether any data is entered into the 'message' string. This is shown below:
<%
If not Request.Form("message")="" THEN
APPLICATION.LOCK
Application("txt13") = Application("txt12")
Application("txt12") = Application("txt11")
Application("txt11") = Application("txt10")
Application("txt10") = Application("txt9")
Application("txt9") = Application("txt8")
Application("txt8") = Application("txt7")
Application("txt7") = Application("txt6")
Application("txt6") = Application("txt5")
Application("txt5") = Application("txt4")
Application("txt4") = Application("txt3")
Application("txt3") = Application("txt2")
Application("txt2") = Application("txt1")
Application("txt1") = "<B>" & Request.Cookies("chatname") & ":</B>" & Request.Form("message")
APPLICATION.UNLOCK
END IF
%>
As you can see above the validation check, checks that if the message string value is not empty then to continue and add the new message line to the lines of text using the 'application()' function. This as you can see is done like before. You may also notice that if the message value is empty when the user submits it nothing happens and no new messages are displayed. Now you may also wonder why all the = signs and the 13 text lines needed. Well, this is because once txt1 is given a new value like above, then the previous txt1 will be lost. So in order to prevent this we are constantly updated txt1 to txt2 and so on, so that every time txt1 is given a new value the previous values will not be lost. Now we shall see how these lines of messages are displayed on the active chat window. This is done using the display.asp file. Here is the code for this file:
<HTML>
<HEAD><TITLE>Kumar's Online Chat</TITLE>
<META HTTP-EQUIV="REFRESH" CONTENT="3; display.asp">
</HEAD>
<BODY>
<FONT SIZE=2>
<%=Application("txt13")%><BR>
<%=Application("txt12")%><BR>
<%=Application("txt11")%><BR>
<%=Application("txt10")%><BR>
<%=Application("txt9")%><BR>
<%=Application("txt8")%><BR>
<%=Application("txt7")%><BR>
<%=Application("txt6")%><BR>
<%=Application("txt5")%><BR>
<%=Application("txt4")%><BR>
<%=Application("txt3")%><BR>
<%=Application("txt2")%><BR>
<%=Application("txt1")%><BR>
</FONT>
</BODY>
</HTML>
As you can see above it just an ASP file displaying some lines of text. These lines of text are the lines that we were updating using the 'application()' function. Here in this file, they are just being displayed. As you can also see that this page refreshes every three seconds. This is required because, when two users are chatting they will be constantly updating the text lines. But what will be displayed is what was there when the page was opened. So, in order to display the new messages this window will need to be refreshed so that it is being constantly updated with the new text values. Now that brings us to the end of part 2.
In this section we will look at display.asp and the message.asp files. Let's leave out the display.asp for some time and concentrate at the message.asp file.
The message.asp file allows the user to input messages so that that he can chat with others. Now let's see how this is done. Firstly we need to again declare a variable so that the messages can be stored somewhere before it is sent to the text lines. This is done like before.
<%
Dim message
%>
Secondly, we need to create a html form as a medium for the user to enter his messages and chat. So let's do that now.
<HTML>
<HEAD>
<TITLE>Kumar's Online Chat Message Dialogue</TITLE>
</HEAD>
<BODY BGCOLOR="CC99FF">
<CENTER>
<FORM METHOD="POST" ACTION="message.asp">
<FONT SIZE=2>Enter your message in the text box below and click Send Message to Chat.</FONT>
<TABLE BORDER=0 CELLSPACING=0>
<TR>
<TD>INPUT NAME="message" TYPE="TEXT" SIZE=30></TD>
<TD><INPUT TYPE="Submit" Value="Send Message"></TD>
<TD> </TD>
<TD VALIGN=TOP><A HREF="logoff.asp" TARGET="_top"><IMG SRC="logoff.jpg" BORDER="NO"></A></TD>
</TABLE>
</FORM>
</CENTER>
<BODY>
</HTML>
As you can see above a form is created that posts messages to this same file message.asp. This means that after the user enters his message and submits it. It is sent to this same file. Then a verification check is done to check whether any data is entered into the 'message' string. This is shown below:
<%
If not Request.Form("message")="" THEN
APPLICATION.LOCK
Application("txt13") = Application("txt12")
Application("txt12") = Application("txt11")
Application("txt11") = Application("txt10")
Application("txt10") = Application("txt9")
Application("txt9") = Application("txt8")
Application("txt8") = Application("txt7")
Application("txt7") = Application("txt6")
Application("txt6") = Application("txt5")
Application("txt5") = Application("txt4")
Application("txt4") = Application("txt3")
Application("txt3") = Application("txt2")
Application("txt2") = Application("txt1")
Application("txt1") = "<B>" & Request.Cookies("chatname") & ":</B>" & Request.Form("message")
APPLICATION.UNLOCK
END IF
%>
As you can see above the validation check, checks that if the message string value is not empty then to continue and add the new message line to the lines of text using the 'application()' function. This as you can see is done like before. You may also notice that if the message value is empty when the user submits it nothing happens and no new messages are displayed. Now you may also wonder why all the = signs and the 13 text lines needed. Well, this is because once txt1 is given a new value like above, then the previous txt1 will be lost. So in order to prevent this we are constantly updated txt1 to txt2 and so on, so that every time txt1 is given a new value the previous values will not be lost. Now we shall see how these lines of messages are displayed on the active chat window. This is done using the display.asp file. Here is the code for this file:
<HTML>
<HEAD><TITLE>Kumar's Online Chat</TITLE>
<META HTTP-EQUIV="REFRESH" CONTENT="3; display.asp">
</HEAD>
<BODY>
<FONT SIZE=2>
<%=Application("txt13")%><BR>
<%=Application("txt12")%><BR>
<%=Application("txt11")%><BR>
<%=Application("txt10")%><BR>
<%=Application("txt9")%><BR>
<%=Application("txt8")%><BR>
<%=Application("txt7")%><BR>
<%=Application("txt6")%><BR>
<%=Application("txt5")%><BR>
<%=Application("txt4")%><BR>
<%=Application("txt3")%><BR>
<%=Application("txt2")%><BR>
<%=Application("txt1")%><BR>
</FONT>
</BODY>
</HTML>
As you can see above it just an ASP file displaying some lines of text. These lines of text are the lines that we were updating using the 'application()' function. Here in this file, they are just being displayed. As you can also see that this page refreshes every three seconds. This is required because, when two users are chatting they will be constantly updating the text lines. But what will be displayed is what was there when the page was opened. So, in order to display the new messages this window will need to be refreshed so that it is being constantly updated with the new text values. Now that brings us to the end of part 2.