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

I have a function to convert HTML code to HTML. It works fine, but for some reason I try to use it in some text today and get the following error:

Microsoft VBScript runtime error '800a000d' Type mismatch: 'UnChkString' /manage/solutions_delete.asp, line 22 

I am using this function:

 <%= UnChkString(solution_desc) %> 

Variable solution_desc :

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

The field through which the database pulls solution_desc from is a text field.

My UnChkString Function:

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

HTMLDecode Function:

 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 even tried:

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

no luck.

+7
source share
4 answers

Sometimes it's best to just reread the error very carefully. Consider this piece of VBS:

  DoStuff("Hello World") 

Since DoStuff not defined and Option Explicit does not exist, I get:

Error: Type Mismatch: "DoStuff"

Your mistake: Type mismatch: 'UnChkString' . He did not complain that the parameter passed his complaints about UnChkString . I assume that you have ported most of the basic VBScript programs, you do not have Option Explicit at the top of the code. It's necessary.

For some unknown reason, from the code you sent so far, the code at the point where <%= UnChkString(solution_desc) %> is executed, the script engine does not have a UnChkString function, therefore, you see an error. I suspect that turning on Option Explicit will show the problem (and also make you Dim all your variables).

+7
source

I agree with Anthony that you should use Option Explicit at the top of your ASP pages.

I suspect the cause is a missing or incorrect include file

I can reproduce this using the code below, where I either delete

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

or reject 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> 
+3
source

Replace string with vStr and change slightly.

Try as follows: -

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

To fix this, you need to first check if it has a char string in it, do it ..

 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 

BUT..

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

This should fix your Type Mismatch problem. Do not ask me why this works.

0
source

All Articles