<%
dim Conn
dim WordRs
Set Conn = Server.CreateObject("ADODB.connection")
' ConnString = "PROVIDER=MICROSOFT.JET.OLEDB.4.0;DATA SOURCE="+Server.MapPath("../../db/Words.mdb")
conn.ConnectionString="Provider=Microsoft.Jet.OLEDB.4.0"
Conn.Open server.mappath("words.mdb")
For Each ConnError in Conn.Errors
Response.Write( ConnError.Description+" ")
Next
Set WordRs = CreateObject("ADODB.Recordset")
if (UCase(Request("Submit")) = "NEW") OR (Request("Submit")="" AND Request( "NewWord" ) ="") then
if Session("First")="" Then
First="Cat"
Session("First")=First
Else
First=Session("First")
End if
if Session("Last")="" Then
Last="Dog"
Session("Last")=Last
Else
Last=Session("Last")
End if
Session("FirstLength")=0
Session("LastLength")=0
Session("GotTargets")=""
Session("Done")=""
if Session("Message")<>"" then
%>
<%=Session("Message")%>
<% end if
Session("Message")=""
%>
<%
Instructions
%>
Top
<%
else ' you already have the targets
dim Prev
dim NewWord
'On Error Resume Next
if Session("GotTargets")="" then
First = Request("First")
if First <> "" then
Query ="Select Word from Words WHERE Word='"+First+"'"
WordRs.Open Query, Conn
if WordRs.EOF=true then
Session("Message")=First+" is not in the Dictionary "
end if
WordRS.Close
else
Session("Message")="The first word cannot be blank "
end if
Last = Request("Last")
if Last <> "" then
Query ="Select Word from Words WHERE Word='"+Last+"'"
WordRs.Open Query, Conn
if WordRs.EOF = true then
Session("Message")=Session("Message")+Last+" is not in the Dictionary "
end if
else
Session("Message")=Session("Message")+"The last word cannot be blank "
end if
WordRS.Close
if Len(First)<>Len(Last) Then
Session("Message")=Session("Message")+"The two target words must be the same length"
elseif UCase(First)=UCase(Last) Then
Session("Message")=Session("Message")+"The two target words should not be the same"
end if
Session("First") = First
Session("Last") = Last
if Session("Message")<>"" then
Response.Redirect( "catdog.asp" )
else
Session("GotTargets")="True"
end if
end if
First = Session("First")
Last = Session("Last")
if Request("Submit")="Undo one from Start" then
if Session("FirstLength") > 0 then
Session.Contents.Remove("First"+CStr(Session("FirstLength")))
Session("FirstLength") = Session("FirstLength")-1
end if
elseif Request("Submit")="Undo one from End" then
if Session("LastLength") > 0 then
Session.Contents.Remove("Last"+CStr(Session("LastLength")))
Session("LastLength") = Session("LastLength")-1
end if
elseif Request("NewWord") <>"" Then
NewWord = Request("NewWord")
Query ="Select Word from Words WHERE Word='"+NewWord+"'"
WordRs.Open Query, Conn
if WordRs.EOF=true then
Session("Message")=NewWord+" is not in the Dictionary "
end if
if Session("Message")="" then
if Len(NewWord)<>Len(First) then
Session("Message")="The new word must be the same length as the first word "
end if
end if
if Session("Message")="" then 'the word is good (we know add or enter was pressed)
if Session("FirstLength")>0 then
Field ="First"+CStr(Session("FirstLength"))
Prev = Session(Field)
else
'Response.Write("Nothing in first")
Prev = First
end if
Prev1=UCase(Prev)
NewWord1=UCase(NewWord)
if Legal(NewWord,Prev) then
if UCase(NewWord) <> UCase(Prev) then
Session("FirstLength")=Session("FirstLength")+1
Field="First"+Cstr(Session("FirstLength"))
Session(Field)=NewWord
end if
else
if Session("LastLength")>0 then
Field ="Last"+CStr(Session("LastLength"))
PrevL = Session(Field)
else
PrevL = Last
end if
PrevL1=UCase(PrevL)
if Legal(NewWord1,PrevL1) then
if UCase(NewWord) <> UCase(PrevL) then
Session("LastLength")=Session("LastLength")+1
Field="Last"+Cstr(Session("LastLength"))
Session(Field)=NewWord
end if
else
Session("Message")=NewWord+" does is not a valid change from either "+Prev+ " or "+PrevL
end if
end if
end if 'got a good new word
if Session("Message")="" And (Session("FirstLength")>0 OR Session("LastLength")>0) then
F1="First"+CStr(Session("FirstLength"))
F2="Last"+CStr(Session("LastLength"))
if UCase(Last)=UCase(Session(F1)) OR UCase(First)=UCase(Session(F2)) OR UCase(Session(F1))=UCase(Session(F2)) Then
Session("Message") ="Great, you have solved the problem! "
Session("Done")="TRUE"
end if
end if
WordRS.Close
end if ' new is not blank
%>
Instructions
<%
if Session("Message")<>"" then
%>
<%=Session("Message")%>
<% end if
Session("Message")=""
%>
Top
<%
Instructions
end if
%>