Classic Asp: I'm Getting a Type Mismatch Error When I Shouldn't

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.

4

4 Answers

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).

1

I agree with Anthony's opinion that you should be using Option Explicit at the top of your ASP pages.

I suspect the cause is a missing or malformed include file

I can replicate this with the code below where I either remove

<!--#include file="include-functions.asp"-->

or malform the call by changing it to

<!-#include file="include-functions.asp"-->


include-functions.asp
<%
Function UnChkString(string)     
UnChkString = Replace(string,"[%]","%")     
UnChkString = HTMLDecode(UnChkString) 
End Function 
%>


index.asp
<html xmlns="">
<head>
<title></title>
</head>
<body>
    <!--#include file="include-functions.asp"-->
<%

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


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 

%>
<%= UnChkString(solution_desc) %> 
</body>
</html>

Replace string to vStr and modified slightly.

Try this way:-

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

In order to fix it, You need to first check if the string has the char in it, do this..

Function HTMLDecode(byVal sText)
    HTMLDecode = sText
    If Instr(HTMLDecode,"&amp;") Then HTMLDecode = Replace(HTMLDecode, "&amp;" , Chr(38))
    If Instr(HTMLDecode,"&amp;") Then HTMLDecode = Replace(HTMLDecode, "&amp;" , "&")
    If Instr(HTMLDecode,"&quot;") Then HTMLDecode = Replace(HTMLDecode, "&quot;", Chr(34))
    If Instr(HTMLDecode,"&rsquo;") Then HTMLDecode = Replace(HTMLDecode, "&rsquo;", Chr(39))
    If Instr(HTMLDecode,"&lt;") Then HTMLDecode = Replace(HTMLDecode, "&lt;"  , Chr(60))
    If Instr(HTMLDecode,"&gt;") Then HTMLDecode = Replace(HTMLDecode, "&gt;"  , Chr(62))
    If Instr(HTMLDecode,"&nbsp;") Then HTMLDecode = Replace(HTMLDecode, "&nbsp;", Chr(32))

    For I = 1 to 255
        If Instr(HTMLDecode, "&#" & I & ";") Then HTMLDecode = Replace(HTMLDecode, "&#" & I & ";", Chr(I))
    Next
End Function

And..

 Function UnChkString(vStr)
     UnChkString = vStr
     If Instr(vStr,"[%]") Then vStr = Replace(vStr,"[%]","%")
 End Function

That should fix your Type Mismatch issue. Don't ask me why, it just works.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Alexander Ross

Alexander Ross

Gaming, Esports & Interactive Media Writer

Alexander Ross has covered the video game industry for a decade, writing deep dives on game design, esports tournaments, VR developments, and gaming culture.

Share this article
Twitter Facebook Pinterest