Despite the simplicity of this project, it contains all the events in the WebClass event sequence. Use the debugger to step through the code. This is what you should see:
When the WebClass starts, the code in the Start event sets the NextItem property of the WebClass to the showTable WebItem.
Before displaying the WebItem, the WebClass fires the showTable_Respond event, which opens the database, retrieves the contents of the Authors table, and formats the HTML return string.
Here's a closer look at the Respond event code. After retrieving the contents of the Authors table, the code loops through the field names to create the first row. It creates the row (<tr></tr> tags) and a column (<td></td>) for each field, places each field name in the center of the column (align="center"), and displays the field name in bold text (<b></b> or <strong></strong>). Finally, it closes the row.
s = s & "<tr>"
For Each F In R.Fields
s = s & "<td align=""center""><b>" & F.Name & "</b></td>"
Next
s = s & "</tr>"
Next, the code loops through the recordset. For each row, it tests the value of each column. If the value is Null, it adds a non-breaking space ( ). If you don't do this, the browser creates the null table cell with no border.
s = s & "<tr>"
While Not R.EOF
s = s & "<tr>"
For Each F In R.Fields
If IsNull(F.Value) Then
s = s & "<td> </td>"
Else
s = s & "<td>" & F.Value & "</td>"
End If
Next
s = s & "</tr>"
R.MoveNext
Wend
Finally, the code closes the recordset and the connection. Although VB destroys local variables when the method completes, you should get into the habit of destroying object variables (setting them to nothing) yourself. When you're working with databases particularly, you want to close any connections or free the table locks as quickly as possible. Remember, the Web is a multiuser medium. You should get in the habit of writing code as if a million people might be using your application. (Maybe they will be!)