Classic ASP: I'm getting a type mismatch error when I shouldn't

James picture James · Mar 8, 2012 · Viewed 46.6k times · Source

I have a function for turning HTML encoded text back into HTML. It works great normally, but for some reason, I try to use it on some text today, and get the following error:

Microsoft VBScript runtime error '800a000d'

Type mismatch: 'UnChkString'

/manage/solutions_delete.asp, line 22

The line I am using this function on is:

<%= UnChkString(solution_desc) %>

The solution_desc variable is:

&lt;p&gt;Here is a description of what this solution is all about.&lt;/p&gt;

The field the database is pulling the solution_desc from is a text field.

My UnChkString function is:

Function UnChkString(string)
    UnChkString = Replace(string,"[%]","%")
    UnChkString = HTMLDecode(UnChkString)
End Function

The HTMLDecode function is:

Function HTMLDecode(sText)
    Dim I
    sText = Replace(sText, "&amp;" , Chr(38))
    sText = Replace(sText, "&amp;" , "&")
    sText = Replace(sText, "&quot;", Chr(34))
    sText = Replace(sText, "&rsquo;", Chr(39))
    sText = Replace(sText, "&lt;"  , Chr(60))
    sText = Replace(sText, "&gt;"  , Chr(62))
    sText = Replace(sText, "&nbsp;", Chr(32))
    For I = 1 to 255
        sText = Replace(sText, "&#" & I & ";", Chr(I))
    Next
    HTMLDecode = sText
End Function

EDIT

I've even tried:

<%= UnChkString(CStr(solution_desc)) %>

with no luck.

Answer

AnthonyWJones picture AnthonyWJones · Mar 8, 2012

Sometimes its best to just re-read the error very carefully. Consider this chunk of VBS:

 DoStuff("Hello World")

Since DoStuff is not defined nor is there an Option Explicit I get:

Error: Type mismatch: 'DoStuff'

Your error is: Type mismatch: 'UnChkString'. Its not complaining about the parameter being passed its complaining about UnChkString itself. My guess is you have committed the most basic of VBScript programmming goofs, you don't have a Option Explicit at the top of you code. This is a must.

For reasons unclear form the code you posted so far the code at the point that <%= UnChkString(solution_desc) %> is being executed the script engine does not have a function UnChkString, hence the error you are seeing. I suspect that inclusion of Option Explicit will reveal the problem (as well as forcing you to Dim all your variables).