<% 'parameter inputs '1. NextQuestion : number of next question to diplay starts at 1 '2. QuizType: options: Reptiles_Common, Amphibians_Common, any other param does reps & amphibs If Len(Request.QueryString("NextQuestion")) < 1 then NextQuestion = 1 'count number of entries in quiz database Dim Counter Counter = GetNumberOfEntries() 'randomly select ten unique entries Dim Questions(10), Rnum, F, G, Exists, QuestionString, QuestionNo Randomize For F = 1 to 10 do 'Generate random number Rnum = Int((counter-1+1)*Rnd+1) Exists = false 'Check if number already selected for G = 1 to 10 If Questions(G) = Rnum then Exists = true end if Next 'G 'check if reptiles only quiz If Request.QueryString("QuizType") = "Reptiles_Common" then 'reject non-reptile animals If GetAnimalType(Rnum) <> "reptile" then Exists = true 'hence ingore this entry as it is not a reptile End if End if 'check if amphibians only quiz If Request.QueryString("QuizType") = "Amphibians_Common" then 'reject non-amphibian animals If GetAnimalType(Rnum) <> "amphibian" then Exists = true 'hence ingore this entry as it is not an amphibian End if End if 'Allocate accepted random number to array string if not Exists then Questions(F) = Rnum end if loop until Exists = false next 'F 'Compile a comma-delimited string of question numbers QuestionString = "" For F = 1 to 9 QuestionString = QuestionString & Questions(F) & "," Next 'F QuestionString = QuestionString & Questions(10) Else 'if NextQuestion <> 1 NextQuestion = Request.QueryString("NextQuestion") QuestionString = Request.QueryString("QuestionString") End If %> <% 'Start timer If request.querystring("StartTime") = "" then StartTime = Time else StartTime = Request.QueryString("StartTime") end If %> <% if Cint(NextQuestion) <= 10 then 'if end of quiz, don't risk out of range errors 'Get numer of photograph for this question PicNumber = GetPictureNo(QuestionString, NextQuestion) 'get picture URL ImagePath = GetPictureURL(PicNumber) end if 'end of question below 10 check %> <% 'determine body and form types If Cint(NextQuestion) > 10 Then FormName = "SARG_Quiz_Results.asp" BodyScript = " onload=" & Chr(34) & "document.myform.submit()" & Chr(34) Else FormName = "SARG2_Quiz_Questions_Buttons2.asp" BodyScript = "" End If %> Surrey Amphibian and Reptile Group (SARG) - SARG ID Quiz Questions >

Question: <%=NextQuestion%> of 10

<% 'automatically add all passed parameters to this form as passed parameters to next form For Each Field In Request.Querystring If (Field <> "NextQuestion") AND (Field <> "StartTime") then Response.write("") End if Next If NextQuestion = 1 then %> <% End if %>

<%=Replace(Request.QueryString("QuizType"),"_"," ")%>

" />
<% Select Case Request.QueryString("QuizType") Case "Amphibians_Common" Call FrogButtons Call ToadButtons Call NewtButtons Case "Reptiles_Common" Call SnakeButtons Call LizardButtons Case Else Call SnakeButtons Call LizardButtons Call FrogButtons Call ToadButtons Call NewtButtons End Select %>
<% SoundFile = GetSoundFile(PicNumber) Set fs=Server.CreateObject("Scripting.FileSystemObject") 'response.write(fs.FileExists(Server.MapPath("/SARG/17000-IDquiz/" & SoundFile))) If (fs.FileExists(Server.MapPath("/SARG/17000-IDquiz/" & SoundFile))) = True Then SoundFile = "./" & SoundFile 'explicitly in same directory %>

Your browser cannot play this audio file.

<% End If set fs=nothing %>

<% FUNCTION GetPictureNo(QuizString, QuizIndex) Dim Start, NumberArray(11), F, Length Start =1 'build array of start positions of entries NumberArray(1)=1 For F = 2 to 10 NumberArray(F) = InStr(Start, QuizString, ",", 1) + 1 Start = NumberArray(F) Next 'F NumberArray(11) = Len(QuizString) + 2 Start = NumberArray(QuizIndex) Length = NumberArray(QuizIndex+1) - NumberArray(QuizIndex) - 1 GetPictureNo = Cint(Mid(Cstr(QuizString), Start , Length)) END FUNCTION FUNCTION GetPictureURL(PictureNumber) 'Find path and filename of photograph for this question Dim LineIn, Line Set FS = Server.CreateObject("Scripting.FileSystemObject") Set RS = FS.OpenTextFile(Server.MapPath("/SARG/17000-IDquiz/SARG_Quiz.XML"),1) counter = 0 Do Do LineIn = RS.Readline Loop Until (LineIn = "") OR (LineIn = "" ) If LineIn <> "" then LineIn = RS.Readline Line = RemoveXMLtag(LineIn) if Cint(Line) = Cint(PictureNumber) Then LineIn = RS.Readline LineIn = RS.Readline GetPictureURL = RemoveXMLtag(LineIn) end if End if Loop Until (RS.AtEndOfStream) 'Tidy up resources by closing file RS.Close Set FS = Nothing END FUNCTION FUNCTION RemoveXMLtag(XMLstring) Position = Cint(InStr(1, Cstr(XMLstring), ">", 1)) Start = Position + 1 Length = Len(Cstr(XMLstring)) - Position - Position -1 RemoveXMLtag = mid(Cstr(XMLstring), Start, Length) END FUNCTION FUNCTION GetNumberOfEntries() Dim LineIn Set FS = Server.CreateObject("Scripting.FileSystemObject") Set RS = FS.OpenTextFile(Server.MapPath("/SARG/17000-IDquiz/SARG_Quiz.XML"),1) GetNumberOfEntries = 0 Do LineIn = RS.Readline If LineIn = "" then GetNumberOfEntries = GetNumberOfEntries + 1 end if Loop Until (RS.AtEndOfStream) 'Tidy up resources by closing file RS.Close Set FS = Nothing END FUNCTION FUNCTION GetAnimalType(QuestionNumber) Dim LineIn, KeyString KeyString = "" & Cstr(QuestionNumber) & "" Set FS = Server.CreateObject("Scripting.FileSystemObject") Set RS = FS.OpenTextFile(Server.MapPath("/SARG/17000-IDquiz/SARG_Quiz.XML"),1) Do LineIn = RS.Readline Loop Until (RS.AtEndOfStream) OR (LineIn = KeyString) If (LineIn = Keystring) Then LineIn = RS.Readline GetAnimalType = RemoveXMLtag(LineIn) End if 'Tidy up resources by closing file RS.Close Set FS = Nothing END FUNCTION FUNCTION GetCommonNameAnswer(QuizNumber) 'note this function has been buggered to send the incorrect species name if the 'animal is not an adult, as it is used to initiate the sound files. 'Find path and filename of photograph for this question Dim LineIn, Line Set FS = Server.CreateObject("Scripting.FileSystemObject") Set RS = FS.OpenTextFile(Server.MapPath("/SARG/17000-IDquiz/SARG_Quiz.XML"),1) counter = 0 Do Do LineIn = RS.Readline Loop Until (LineIn = "") OR (LineIn = "" ) If LineIn <> "" then LineIn = RS.Readline 'quiz question number 'response.write("Q number: " & LineIn & "
") Line = RemoveXMLtag(LineIn) if Cint(Line) = Cint(QuizNumber) Then LineIn = RS.Readline 'Reptile or Amphibian LineIn = RS.Readline 'Image URL LineIn = RS.Readline 'Common Name 'response.write("Common Name: " & LineIn & "
") GetCommonNameAnswer = RemoveXMLtag(LineIn) LineIn = RS.Readline ' LineIn = RS.Readline ' LineIn = RemoveXMLtag(RS.Readline) ' If LineIn <> "adult" then GetCommonNameAnswer = "Not an adult" End if end if End if Loop Until (RS.AtEndOfStream) 'Tidy up resources by closing file RS.Close Set FS = Nothing END FUNCTION FUNCTION GetSoundFile(QuestionNumber) Dim Pos '-- If a sound file exists, then play it ! --> GetSoundFile = Trim(GetCommonNameAnswer(QuestionNumber)) & ".wav" Do Pos = Instr(GetSoundFile, " ") If Pos > 0 then GetSoundFile = Left(GetSoundFile,Pos-1) & "_" & Right(GetSoundFile, Len(GetSoundFile)-Pos) end if Loop until Instr(GetSoundFile, " ") = 0 END FUNCTION SUB SnakeButtons Dim Species Species = Array("Adder","Grass snake","Smooth snake","Aesculapian snake") Response.write("
") Response.write("Snakes: ") For Each Entry in Species Response.write("") Response.write(" ") Next Response.write("
") End Sub SUB LizardButtons Dim Species Species = Array("Common lizard","Sand lizard","Slow worm","Common wall lizard","Western green lizard") Response.write("
") Response.write("Lizards: ") For Each Entry in Species Response.write("") Response.write(" ") Next Response.write("
") End Sub SUB FrogButtons Dim Species Species = Array("Common frog","Pool frog","Edible frog","Marsh frog","North-American Bullfrog","European tree frog") Response.write("
") Response.write("Frogs: ") For Each Entry in Species Response.write("") Response.write(" ") Next Response.write("
") End Sub SUB ToadButtons Dim Species Species = Array("Common toad","Natterjack toad","Midwife toad") Response.write("
") Response.write("Toads: ") For Each Entry in Species Response.write("") Response.write(" ") Next Response.write("
") End Sub SUB NewtButtons Dim Species Species = Array("Great crested newt","Smooth newt","Palmate newt","Alpine newt") Response.write("
") Response.write("Newts: ") For Each Entry in Species Response.write("") Response.write(" ") Next Response.write("
") End Sub %>