_Server-Side Scripting in Visual Basic_
by Al Williams

Example 1:

(a)

Copyright 1997 by Al Williams


(b)

<HTML>
<HEAD>
<TITLE>A Demo Page</TITLE>
</HEAD>
<BODY>
Welcome to this meaningless page.
<!--#include file="copy.inc"-->
</BODY>
<HTML>


Example 2:

(a)

The first few Fibonacci numbers:<P>
<% n1=0 n2=1 
      for i= 1 to 100 %>
        Number <%=I %>: <%= n1+n2 %><P>
         <% old=n1
              n1=n2
              n2=old+n2 
       next %>

(b)
<% If flag=True %>
   You are authorized to proceed_
<% else %>
   <B>Unauthorized Access Attempted!</B>
<% end if %>


Listing One
<!--#include file="adovbs.inc" -->
<HTML>
<HEAD>
<TITLE>Report Your Sightings!</TITLE>
</HEAD>
<BODY>
<!-- decide if data is present
     If data is present, process
     Otherwise, show form -->
<% if Request("Content_Length")=0 then %>
<H1>Report your King Sightings Here!<BR>
</H1>
<FORM NAME="KingForm" ACTION="ddjrpt.asp" METHOD="POST">
<PRE WIDTH=132>
<FONT SIZE=2>Date:     </FONT>
<INPUT NAME="KDate" VALUE="" MAXLENGTH="8" SIZE=8>
<FONT SIZE=2 FACE="Courier New">
I've seen the King before: </FONT>
<INPUT TYPE="CHECKBOX" NAME="Before">

<FONT SIZE=2 FACE="Courier New">Location: </FONT>
<INPUT NAME="Loc" VALUE="" MAXLENGTH="128" SIZE=64>
<FONT SIZE=2 FACE="Courier New">

<FONT SIZE=2 FACE="Courier New">Your name: </FONT>
<INPUT NAME="Name" VALUE="" MAXLENGTH="128" SIZE=64>
<FONT SIZE=2 FACE="Courier New">

Comments:
</FONT>
<TEXTAREA NAME="Comment" ROWS=3 COLS=80>
</TEXTAREA>
</PRE>
<INPUT TYPE=SUBMIT NAME="Enter" VALUE="Enter" >
</FORM>
<%else %>
<% ' Using record set which is easy, but an Insert would
   ' have better performance (see DDJFIND.ASP)
   Set Conn = Server.CreateObject("ADODB.Connection")
   Conn.Open "KingSight","guest",""
   set RS=Server.CreateObject("ADODB.RecordSet")
   Conn.BeginTrans ' start a unit of work
   rs.Open "Sighting", Conn, adOpenStatic, adLockOptimistic
   rs.AddNew ' new record
   rs("Date")=CDate(Request("KDate"))
   if Request("Before")="on" then
     rs("Before")=-1
   else
     rs("Before")=0
   end if
   rs("Location")=Request("Loc")
   rs("Name")=Request("Name")
   rs("Comment")=Request("Comment")
   rs("subtime")=now
   rs.Update
   Conn.CommitTrans
   rs.Close
   Conn.Close
%>
<H1> Thanks for your report </H1>
<P>Thank you very much!
<A HREF=ddjfind.asp>Click here to view recent sightings!</A>
<% end if %>
</BODY>
</HTML>


Listing Two
<!--#include file="adovbs.inc" -->
<HTML>
<HEAD>
<TITLE>Find the King</TITLE>
</HEAD>
<BODY>
<H1>Recent King Sightings: </H1>
<!-- Create a connection to the database -->
<% Set Conn = Server.CreateObject("ADODB.Connection")
   Conn.Open "KingSight","guest",""
   ' Execute SQL select
   SQL="Select * from Sighting order by date desc"
   set RS = Conn.Execute(SQL)
%>
<P>
<TABLE BORDER=1>
<TR>
  <!-- print headers -->
  <!-- last field is hidden -->
  <% For i = 0 to RS.Fields.Count - 2 %>
     <TD><B><%= RS(i).Name %></B></TD>
  <% Next %>
</TR>
<!-- print table (except for last field -->
<% Do While Not RS.EOF %>
  <TR>
  <% For i = 0 to RS.Fields.Count - 2 %>
       <TD VALIGN=TOP>
    <% if RS(i).Name<>"Before" then %>
       <%= RS(i) %>
    <% else %>
       <% if RS(i)=0 then %>
         N
       <% else %>
         Y
       <% end if %>
    <% end if %>
       </TD>
  <% Next %>
  </TR>
<%
  RS.MoveNext  <!-- go to next record -->
  Loop
  RS.Close
  Conn.Close
%>
</TABLE>
<P>
Be sure to add your sightings by clicking
<a href="ddjrpt.asp">here</A>.
</BODY>
</HTML>



