CSCI 4230
Software Tools
Fall 1999
Suugested Solution to Homework #7

(1)    For example,

<BODY bgcolor=#CCFFFF>
<%

SSNum = Request.QueryString("SSNum")

ExcelFile = "data4.xls"
ExcelFilePath = Server.MapPath(ExcelFile) ' assumes file in current directory
ConnString = "DRIVER={Microsoft Excel Driver (*.xls)};ReadOnly=1;DBQ=" & _
              ExcelFilePath
Set Conn = Server.CreateObject("ADODB.Connection")

Conn.Open ConnString

set rstemp=Conn.execute("[a1:t40]")
lastfield=rstemp.fields.count -1

'  Store all heading descriptions in an array.
Dim Heading(19)
'  Store Headings On The Table of Field Names
for i=0 to lastfield
   Heading(i) = rstemp.fields(i).name
next

Dim Student(19)
Found = false
do while not rstemp.eof
   '  Assume that SSNum is always in the second column
   if rstemp.fields(1) = SSNum then
      for i = 0 to lastfield
          Student(i) = rstemp.fields(i).value
      next
      Found = true
      '  Skip remaining students.
      do
          rstemp.movenext
      loop while rstemp.fields(0) <> ""
      rstemp.movenext
      exit do
   end if
   rstemp.movenext
 loop

if Found then
   '  Print name.
   Response.write "<h2 style='color:green'>" & Student(0) & ", your grade so far:</h2>"
%>
<table border=1>
   <tr>
        <td>&nbsp;</td>
<%  '  Print table heading
    for i = 2 to lastfield
        Response.write "<td style='color:blue'>" & Heading(i) & "</td>"
    next
%>
   </tr>
   <tr>
        <td style='color:green'>Your Grade</td>
<%
    '  Print student grade
    for i = 2 to lastfield
        Response.write "<td>"
        if Student(i) <> "" then
           Response.write Student(i)
        else
           Response.write "&nbsp;"
        end if
        Response.write "</td>"
    next
%>
   </tr>

<%  '  Print statistical summary.
    do while not rstemp.eof
        Response.write "<tr><td style='color:blue'>" & rstemp.fields(0) & "</td>"
        for i = 2 to lastfield
            Response.write "<td>" & FormatNumber(rstemp.fields(i),1) & "</td>"
        next
        rstemp.movenext
    loop
%>
</table>
</body>

<%
else
   Response.write "<h2 style='color:green'>Sorry, your username is not in our gradebook.</h2>"
end if
%>
<%   Conn.close  %>

</BDOY>