You need to write the code to process the sign-on and password when the user submits the form. Form submission is an event. Because VB doesn't know which events you'll want to process, you need to connect an item with an event. Right-click the frmSignon entry in the right-hand pane of the WebClass Designer window and select Connect to Custom Event. A new event, called frmSignon, appears under the Signon item (see Figure 5.6).
For now, because you'll want to check for errors before continuing, you'll just write a stub to check the values entered by the user. When the user has entered both values, the event code displays the entered values in the browser. If the user did not enter a valid value for either the sign-on or password, the event code places a message into the Session("msg") variable and redisplays the form.
To add the code, double-click the frmSignon event in the Designer window. The code window opens and your cursor is inside the new event. Enter the following code into the event stub:
Private Sub Signon_frmSignon()
Dim aSignon As String
Dim aPassword As String
Dim action As String
Dim tmpSignon As String
Dim tmpPassword As String
Dim arrSignonInfo As Variant
Dim V As Variant
action = Request.Form("Submit")
Session("LastSignon") = ""
Session("LastPassword") = ""
aSignon = Request.Form("Signon")
aPassword = Request.Form("Password")
If Trim(aSignon) = vbNullString Then
Session("msg") = "You must enter a signon."
Set NextItem = Signon
Exit Sub
End If
Session("LastSignon") = aSignon
If aPassword = vbNullString Then
Session("msg") = "You must enter a password."
Set NextItem = Signon
Exit Sub
End If
Session("LastPassword") = aPassword
End Sub
Make sure you have no more than one browser open. Otherwise, the debugger can get confused. Save the project, then press F8 to step through the project. The Signon screen should look like Figure 5.7.
Tip
When debugging, you need to switch to the browser manually whenever the WebClass completes a response. After running a WebClass many times, stepping may cease to work. In that case, set a breakpoint. The WebClass code window appears when execution reaches the breakpoint. You still need to switch back to the browser manually.
After you enter a sign-on and a password, the application displays the sign-on and password you entered. If you experiment, you'll see that both the sign-on and password are required. The server returns error messages to the browser if either value is missing.
You have the first part of the application running. Now, you're ready to add some more features. You'll need a registration screen into which people will enter information (a sign-on and password) and a database in which to store the registration information they enter. For a large site, you would want to use a real database, but for this practice application, you'll use a file on the server. Each line in the file will contain two string items, the sign-on and password.
Adding the registration screen changes the flow of the program slightly. Figure 5.8 shows the flowchart after adding the registration screen.