Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 936
James Avatar asked Mar 08 '12 14:03

James


1 Answers

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="http://www.w3.org/1999/xhtml">
<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>
like image 89
Nicholas Murray Avatar answered Sep 29 '22 10:09

Nicholas Murray