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 ?????

Dani AI

Generated

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

  • Dump the raw incoming value to confirm what the server sees (temporary debug output).
  • Confirm the cookie was set in a prior request (or use Session if you need the value immediately).
  • If you used subkeys (Response.Cookies("Result")("score") = ...), read the same subkey: Request.Cookies("Result")("score").
  • Validate before converting: use Trim/IsNumeric or Val to avoid calling CInt/CLng on an empty or non-numeric string.

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.

Recommended Answers

All 2 Replies

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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.