Forum Moderators: open

Message Too Old, No Replies

Type Mismatch cint

type mismatch

         

cmatcme

4:18 pm on Feb 24, 2005 (gmt 0)

10+ Year Member



Here's the code for example.asp

If cint(request("q"))<=10 AND cint(request("q"))>=0 Then
response.redirect "example2.asp?e=e"
LINE 3 * ElseIf cint(request("q"))<=29 AND cint(request("q")) >=11 Then *END LINE 3
response.redirect "example2.asp?e=x"
ElseIf cint(request("q"))<=49 AND cint(request("q"))>=30 Then
response.redirect "example2.asp?e=a"
ElseIf cint(request("q"))=50 Then
response.redirect "example2.asp?e=m"
ElseIf cint(request("q"))<=74 AND cint(request("q"))>=51 Then
response.redirect "example2.asp?e=p"
ElseIf cint(request("q"))<=99 AND cint(request("q"))>=75 Then
response.redirect "example2.asp?e=l"
ElseIf cint(request("q"))=100 Then
response.redirect "example2.asp?e=e"
Else
response.redirect "example3.asp"
end if

And the error it brings up is:

Microsoft VBScript runtime error '800a000d'

Type mismatch: 'cint'

/exampl/eexamp/leexam/results.asp, line 3

** PLEASE HELP **

mattglet

4:52 pm on Feb 24, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Your request("q") does not contain a numerical value. CInt() only works when it has a number to convert. If any other data type (i.e. string, or null value) is present, CInt() will error out.

I would suggest first performing a IsNumeric() call on the value you're dealing with.

if IsNumeric(your_value) then
'do something; everything's fine
else
'show error; value is not numeric
end if

cmatcme

5:08 pm on Feb 24, 2005 (gmt 0)

10+ Year Member



I did your advice and edited it slightly

if IsNumeric(q) then
response.write "Q is numeric"
else
response.write "Error Custom"
end if

Q is numeric came up.

Thanx for trying

Staffa

6:00 pm on Feb 24, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Where do you get your
request("q")
from?

If it's the result of a form submit it should be request.form("q")
If it's the result of an Url extension it should be request.querystring("q")

Just so you don't overlook the obvious ;o)

mattglet

7:51 pm on Feb 24, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Actually, request("whatever") should work fine; you're just calling the Request Collection. Request.Form() and Request.Querystring() just break it down further for you.

mattglet

7:53 pm on Feb 24, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Have you outputted your request("q") to see what it actually contains?

i.e.

Response.Write(request("q"))

cmatcme

7:59 pm on Feb 24, 2005 (gmt 0)

10+ Year Member



I just did and this is what is said:

2, 12, 11, 15

You see q is made up of a series of questions in a form. I thought it would add the values up.

<input thing name="q">
<input thing name="q">

If I change the values to

<input thing name="q">
<input thing name="q2">

could someone tell how to add values up:

q+q2 eg. to make a new value ie newq?

mattglet

9:24 pm on Feb 24, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Ah, that makes sense now.

You'll need to do something like this:

intQuestionSum = 0
for each myvalue in request("q")
if isNumeric(myvalue)
intQuestionSum = intQuestionSum + myvalue
end if
next

intQuestionSum should now be your total.

cmatcme

6:27 pm on Feb 25, 2005 (gmt 0)

10+ Year Member



Here's a section of the code:

for each myvalue in request("q14")
if isNumeric(myvalue) then
intQuestionSum = intQuestionSum + myvalue
end if
next

If cint(request("intQuestionSum"))<=10 AND cint(request("intQuestionSum"))>=0 Then
response.redirect "example.asp?im=e"
ElseIf cint(request("intQuestionSum"))<=29 AND cint(request("intQuestionSum"))>=11 Then
response.redirect "example.asp?im=x"

My problem is no matter what value q is and I have checked by getting it to response.write it always redirects you to example.asp?im=x

mattglet

6:46 pm on Feb 25, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



for each myvalue in request("q14")
if isNumeric(myvalue) then
intQuestionSum = cint(intQuestionSum + myvalue)
end if
next

If intQuestionSum <=10 AND intQuestionSum >=0 Then
response.redirect "example.asp?im=e"
ElseIf intQuestionSum <=29 AND intQuestionSum >=11 Then
response.redirect "example.asp?im=x"
End If

Try that.

cmatcme

6:45 pm on Feb 26, 2005 (gmt 0)

10+ Year Member



Yeah! Finally it works! Thanks everybody!