For Next in ASP page

  • Thread starter Thread starter Earl Partridge
  • Start date Start date
E

Earl Partridge

FP 2000, Windows XP
In a For/Next loop I compare the loop counter to another number, where I
know
there is a match, but it is never recognized. For Example..
ChkNbr = 2
For i = 1 to 5
if i = ChkNbr then
do this
exit for
end if
next

The "ChkNbr" is obtained from a Request.form("MyNumber") entry.
I'm guess the loop counter may be a different type "number". I've tried
converting
both to a string (cStr) and no luck.
 
Hi,
The value from the form needs to be cast as int, eg
ChkNbr = cint(request.form("Field"))
for i = 1 to 5
if i = ChkNbr then
' do whatever
exit for
end if
next


Cheers,
Jon
 
I tried adding the parentheses around the from number, and added an else
line. Still won't recognize the match. This "If" check is actually within
another "If".
What is the significance of the parentheses?
The actual code is:
AnsNbr = request.form("R1")

for i = 1 to 5
Choice = rs("Ans" & i)
if left(Choice,1) = "*" then
response.write "found asterisk " & "<BR>"
if AnsNbr = i then
response.write "correct " & Choice & "<BR>"
exit for
end if
end if
next

I get the "Found Asterisk" line but nothing else.
Earl
 
With CINT I get Variable uses an Automation type not supported in
VBScript: 'cInt'
I suppose I can somehow specify something other than VBScript?
Earl
 
I seemed to have resolved it by putting the value from the form in a
different
named variable and then making ChkNbr = that value.
Thanks for the help.
Still curious as to the parentheses around the first For counter?
Earl
 
Back
Top