%@ Language=VBScript%> <% Response.buffer=true ' ************************************************ ' *** Form Name: frmRegister *** ' *** Author: Keith Morneau *** ' *** Date: 8/6/01 *** ' *** Description: *** ' *** This form allows user to enter *** ' *** the student information. *** ' *** *** ' *** Revisions: ' NWH Updated 10/9/03 to remove dependence on clsForm class ' ************************************************* 'store the form element values in the dictionary object Private Sub CreateDict(objDict) Dim item 'loop through all the Form collection members For Each item in Request.Form objDict.Add item, Request.Form(item) Next End Sub 'search through the text file for the student with strFirstName and strLastname Function Search(objDict,strFirstName,strLastName) 'declare variables for FileSystemObject, File, and TextStream Dim objFileSystemObject,objFile,objFS 'declare variables for student record Dim strFirst,strLast,strHomePhone, strWorkPhone, strEMail 'create the FileSystemObject Set objFileSystemObject = CreateObject("Scripting.FileSystemObject") 'create a File object linked to the file specified in the strServerFilePath property Set objFile = objFileSystemObject.GetFile(strServerFilePath) 'open the file as a TextStream object Set objFS = objFile.OpenAsTextStream(1, -2) 'loop through each block of 5 lines of the file - corresponds to a single student Do While Not objFS.AtEndOfStream strFirst = UCASE(objFS.ReadLine) strLast = UCASE(objFS.ReadLine) strHomePhone = objFS.ReadLine strWorkPhone = objFS.ReadLine strEMail = objFS.ReadLine 'test the name of the student against the data from the file If (UCASE(strFirstName) = strFirst) and (UCASE(strLastName) = strLast) Then 'we have a match so save the data strMode = "Browse" objDict.RemoveAll objDict.Add "txtFirstName", strFirstName objDict.Add "txtLastName", strLastName objDict.Add "txtHomePhone", strHomePhone objDict.Add "txtWorkPhone", strWorkPhone objDict.Add "txtEmail", strEMail Search = True objFS.close Exit Function End If Loop 'if we get to here the search failed Search = False 'close the file object objFS.close End Function 'save the details of the new student to the file Public Sub Save(strServFilePath) 'declare variables for FileSystemObject, File, and TextStream Dim objFileSystemObject,objFile,objFS 'instantiate the FileSystemObject Set objFileSystemObject = CreateObject("Scripting.FileSystemObject") 'test the student record file exists If Not objFileSystemObject.FileExists(strServFilePath) Then 'no file so create it Set objFS = objFileSystemObject.CreateTextFile(strServFilePath) Else 'file exists so link to File object Set objFile = objFileSystemObject.GetFile(strServFilePath) 'open the file as a TextStream Set objFS = objFile.OpenAsTextStream(8, -2) End If 'write the data in the dictionary object to the file 'each record is written as 5 lines For Each strItem in colFormElements 'trim off any spaces before writing the line objFS.WriteLine trim(colFormElements.Item(strItem)) Next 'close the file objFS.Close 'clear the TextStream object set objFS = Nothing 'clear the File object set objFile = Nothing 'clear the FileSystemObject object set objFileSystemObject = Nothing End Sub 'Main script Dim objForm,objFileSystemObject Dim strMode, strServerFilePath Dim colFormElements 'set the default search mode strMode = "Browse" Set colFormElements = CreateObject("Scripting.Dictionary") strServerFilePath = Server.Mappath("students.txt") CreateDict colFormElements Set objFileSystemObject = CreateObject("Scripting.FileSystemObject") strServerFilePath = Server.MapPath("students.txt") If objFileSystemObject.FileExists(strServerFilePath) Then strMode = Request.QueryString("Mode") If strMode = "Browse" then If Request.QueryString("txtFirstName")<>"" AND Request.QueryString("txtLastName")<>"" Then If Not Search(colFormElements,Request.QueryString("txtFirstName"),Request.QueryString("txtLastName")) then strMode = "New" colFormElements.RemoveAll colFormElements.Add "txtFirstName", "" colFormElements.Add "txtLastName", "" colFormElements.Add "txtHomePhone", "" colFormElements.Add "txtWorkPhone", "" colFormElements.Add "txtEmail", "" End If End If End If Else strMode = "New" colFormElements.RemoveAll colFormElements.Add "txtFirstName", "" colFormElements.Add "txtLastName", "" colFormElements.Add "txtHomePhone", "" colFormElements.Add "txtWorkPhone", "" colFormElements.Add "txtEmail", "" End If %>
Instructions: You need to fill in this information
so that I can contact you in an emergency.
All mandatory fields have an "*" next to them.
Please fill-in all mandatory fields before hitting Save.