Question : Dropdown list populating code not working

Hello all

I got some code that looks up a word in a database and randomly selects three separate letters to populate three dropdown boxes in a form.

However, it's not getting past the second block of code to decide the letter. When I test it, I get a syntax error at the line:
ElseIf (vRand2>vRand1 And vRand2<vRand3) Then vCheck2 = vRand2
I been looking at the code so long that it's making my eyes hurt. Can you help please?

Here's the code:
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
<%
If Request.Form("process") <> "true" Then
	Dim vCheck1, vCheck2, vCheck3, vLength
	Dim vRand1, vRand2, vRand3
	
	' Get the length of the secret word
	vLength = Len(rsPersonnel("PrivateWord"))
	
	' Randomly choose a character
	Randomize
		vRand1 = Int(rnd*vLength)+1
		
	' Make sure we don't get the same character twice
	Do
		vRand2 = Int(rnd*vLength)+1
	Loop While vRand2 = vRand1
	
	' Make sure we don't get the same character thrice
	Do
		vRand3 = Int(rnd*vLength)+1
	Loop While vRand3 = vRand1 Or vRand3 = vRand2

	' Sort the characters into order, lowest to highest, for each dropdown
	If (vRand1>vRand2 And vRand1>vRand3) Then vCheck1 = vRand1
		ElseIf (vRand1>vRand2 And vRand1<vRand3) Then vCheck2 = vRand1
		ElseIf (vRand1>vRand3 And vRand1<vRand2) Then vCheck2 = vRand1
		ElseIf (vRand1<vRand2 And vRand1<vRand3) Then vCheck1 = vRand1
	End If
	
	If (vRand2>vRand1 And vRand2>vRand3) Then vCheck2 = vRand2
		ElseIf (vRand2>vRand1 And vRand2<vRand3) Then vCheck2 = vRand2
		ElseIf (vRand2>vRand3 And vRand2<vRand1) Then vCheck2 = vRand2
		ElseIf (vRand2<vRand1 And vRand2<vRand3) Then vCheck1 = vRand2
	End If
	
	If (vRand3>vRand1 And vRand3>vRand2) Then vCheck3 = vRand3
		ElseIf (vRand3>vRand1 And vRand3<vRand2) Then vCheck2 = vRand3
		ElseIf (vRand3>vRand2 And vRand3<vRand1) Then vCheck2 = vRand3
		ElseIf (vRand3<vRand1 And vRand3<vRand2) Then vCheck1 = vRand3
	End If 
	
End If
%>
<%
Sub sPopulateDropdown(vStart, vEnd)

' Dynamically populate a dropdown field
Dim i, sWrite
For i = vStart to vEnd
sWrite = "<option value=" & Chr(34) & Chr(i) & Chr(34) & ">" & Chr(i) & "</option>"
Response.Write sWrite
Next
End Sub
%>


and here's the form:
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
<form action="" method="post" name="frmControl">

<table id="formTable">
    <tr>
        <td class="formLabel">&nbsp;</td>
        <td align="center">
        	<input name="pos1" type="hidden" value="<%=vCheck1%>" />
            <%=vCheck1%>
            <select name="cbo1" id="cbo1">
            <% Call sPopulateDropdown(97,122)%>
            <% Call sPopulateDropdown(48,57)%>
            </select>
        </td>
        <td align="center">
        	<input name="pos2" type="hidden" value="<%=vCheck2%>" />
            <%=vCheck2%>
            <select name="cbo2" id="cbo2">
            <% Call sPopulateDropdown(97,122)%>
            <% Call sPopulateDropdown(48,57)%>
            </select>
        </td>
        <td align="center">
        	<input name="pos3" type="hidden" value="<%=vCheck3%>" />
            <%=vCheck3%>
            <select name="cbo3" id="cbo3">
            <% Call sPopulateDropdown(97,122)%>
            <% Call sPopulateDropdown(48,57)%>
            </select>
        </td>
    </tr>
    <tr>
        <td class="formLabel">&nbsp;</td>
        <td colspan="3"><div class="dots">&nbsp;</div></td>
    </tr>
    <tr>
        <td class="formLabel">&nbsp;</td>
        <td colspan="3" align="center"><input name="Submit" type="submit" class="formButton" id="Submit" value="Confirm" /></td>
    </tr>
</table>

<input name="process" type="hidden" value="true" />
</form>						


Many thanks in advance.

P.

Answer : Dropdown list populating code not working

try removing the End If as follow:

      ' Sort the characters into order, lowest to highest, for each dropdown
      If (vRand1>vRand2 And vRand1>vRand3) Then vCheck1 = vRand1
            ElseIf (vRand1>vRand2 And vRand1<vRand3) Then vCheck2 = vRand1
            ElseIf (vRand1>vRand3 And vRand1<vRand2) Then vCheck2 = vRand1
            ElseIf (vRand1<vRand2 And vRand1<vRand3) Then vCheck1 = vRand1
      
      If (vRand2>vRand1 And vRand2>vRand3) Then vCheck2 = vRand2
            ElseIf (vRand2>vRand1 And vRand2<vRand3) Then vCheck2 = vRand2
            ElseIf (vRand2>vRand3 And vRand2<vRand1) Then vCheck2 = vRand2
            ElseIf (vRand2<vRand1 And vRand2<vRand3) Then vCheck1 = vRand2
      
      If (vRand3>vRand1 And vRand3>vRand2) Then vCheck3 = vRand3
            ElseIf (vRand3>vRand1 And vRand3<vRand2) Then vCheck2 = vRand3
            ElseIf (vRand3>vRand2 And vRand3<vRand1) Then vCheck2 = vRand3
            ElseIf (vRand3<vRand1 And vRand3<vRand2) Then vCheck1 = vRand3
Random Solutions  
 
programming4us programming4us