dim num, GOPercent
num = Request.Cookies("Result")
GOPercent = num/25 Type mismatch: '[string: ""]'
Error Type mismatch. But the value i put in Response.cookies("Result") is a CInt(value)
how to solve this ?????
dim num, GOPercent
num = Request.Cookies("Result")
GOPercent = num/25 Type mismatch: '[string: ""]'
Error Type mismatch. But the value i put in Response.cookies("Result") is a CInt(value)
how to solve this ?????
Type mismatch in this scenario almost always means VBScript tried to do math on something that isn’t a number. Common causes: the cookie is empty (""), contains non-numeric text, is stored as a multi-valued cookie (so Request.Cookies returns a collection), or you’re attempting to read a cookie you just set in the same request (cookies set with Response.Cookies are sent to the browser and only come back on the next request). ’s error message shows an empty string being used; ’ suggestion to check for a blank value and that cookies are enabled is correct—extend that with a few extra checks below.
Quick checklist
Safer conversion example:
Dim rawVal, n
rawVal = Trim(CStr(Request.Cookies("Result")))
If Len(rawVal) > 0 And IsNumeric(rawVal) Then
n = CLng(rawVal)
GOPercent = n / 25
Else
' fallback: log, default, or redirect to an error page
GOPercent = 0
End If If the value must be available immediately after you set it on the server, store it in Session or set the cookie and then Redirect so the browser sends it back. Handling validation and the multi-value cookie case will eliminate the Type mismatch and make the code more robust.
Jump to Post— davidcairns 1I'm not sure if you're saying the value you get from num = Request.Cookies("Result") is blank or just that it is a mismatch.
First of all do the following to your code
num = Request.Cookies("Result") If num <> "" Then GOPercent = cInt(num)/25 End IfIf …
I'm not sure if you're saying the value you get from num = Request.Cookies("Result") is blank or just that it is a mismatch.
First of all do the following to your code
num = Request.Cookies("Result")
If num <> "" Then
GOPercent = cInt(num)/25
End If If you are saying you get no value back then check two things
1. You are definately setting Response("Result") to a value
2. Cookies are enabled on the client browser
You are going to need a lot more durable code to run this kind of thing so look in to how to preempt errors and handle issues. This isn't as easy in vbscript as it is in other languages, but there's always a way :)
Thanks.....Solve
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.