Reputation: 3805
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:
<p>Here is a description of what this solution is all about.</p>
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, "&" , Chr(38))
sText = Replace(sText, "&" , "&")
sText = Replace(sText, """, Chr(34))
sText = Replace(sText, "’", Chr(39))
sText = Replace(sText, "<" , Chr(60))
sText = Replace(sText, ">" , Chr(62))
sText = Replace(sText, " ", 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.
Upvotes: 12
Views: 51555
Reputation: 13529
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 = "<p>Here is a description of what this solution is all about.</p>"
Function HTMLDecode(sText)
Dim I
sText = Replace(sText, "&" , Chr(38))
sText = Replace(sText, "&" , "&")
sText = Replace(sText, """, Chr(34))
sText = Replace(sText, "’", Chr(39))
sText = Replace(sText, "<" , Chr(60))
sText = Replace(sText, ">" , Chr(62))
sText = Replace(sText, " ", Chr(32))
For I = 1 to 255
sText = Replace(sText, "&#" & I & ";", Chr(I))
Next
HTMLDecode = sText
End Function
%>
<%= UnChkString(solution_desc) %>
</body>
</html>
Upvotes: 5
Reputation: 13243
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,"&") Then HTMLDecode = Replace(HTMLDecode, "&" , Chr(38))
If Instr(HTMLDecode,"&") Then HTMLDecode = Replace(HTMLDecode, "&" , "&")
If Instr(HTMLDecode,""") Then HTMLDecode = Replace(HTMLDecode, """, Chr(34))
If Instr(HTMLDecode,"’") Then HTMLDecode = Replace(HTMLDecode, "’", Chr(39))
If Instr(HTMLDecode,"<") Then HTMLDecode = Replace(HTMLDecode, "<" , Chr(60))
If Instr(HTMLDecode,">") Then HTMLDecode = Replace(HTMLDecode, ">" , Chr(62))
If Instr(HTMLDecode," ") Then HTMLDecode = Replace(HTMLDecode, " ", 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.
Upvotes: 0
Reputation: 189505
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).
Upvotes: 10
Reputation: 18064
Replace string
to vStr
and modified slightly.
Try this way:-
Function UnChkString(vStr)
vStr = Replace(vStr,"[%]","%")
UnChkString = HTMLDecode(vStr)
End Function
Upvotes: -1