2012-03-08 90 views
7

我有將HTML編碼文本轉換回HTML的功能。它的偉大工程正常,但由於某些原因,我嘗試使用它今天一些文字,並出現以下錯誤:經典ASP:當我不應該出現類型不匹配錯誤

Microsoft VBScript runtime error '800a000d' 

Type mismatch: 'UnChkString' 

/manage/solutions_delete.asp, line 22 

我使用這個功能的線路是:

<%= UnChkString(solution_desc) %> 

solution_desc變量是:

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

領域的數據庫中被甩開了solution_desc是一個文本字段。

我UnChkString功能是:

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

的HTMLDecode功能是:

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(CStr(solution_desc)) %> 

沒有運氣。

+0

哪一行是第22行? – bfavaretto 2012-03-08 14:40:25

+0

@bfavaretto'<%= UnChkString(solution_desc)%>' – James 2012-03-08 14:41:15

+0

也許你從數據庫中獲得'NULL'?錯誤是否發生在您發佈的示例字符串中? – bfavaretto 2012-03-08 14:46:15

回答

7

有時它最好還是重新讀取錯誤非常謹慎。考慮VBS的這個塊:

DoStuff("Hello World") 

由於DoStuff沒有規定也沒有一個Option Explicit我得到:

Error: Type mismatch: 'DoStuff'

你的錯誤是:Type mismatch: 'UnChkString'。它不抱怨參數通過UnChkString本身抱怨。我的猜測是你已經提交了最基本的VBScript編程方法,你的代碼中沒有Option Explicit。這是必須的。

由於原因尚不清楚,所以您發佈的代碼到目前爲止正在執行的代碼爲<%= UnChkString(solution_desc) %>,腳本引擎沒有函數UnChkString,因此您看到的錯誤。我懷疑包含Option Explicit會揭示這個問題(以及迫使你到Dim所有的變量)。

+0

我開始回覆說我希望這很簡單,但是函數腳本會自動加載到每個頁面中,但是無論如何都要檢查。這是原因。我的功能腳本沒有包含在這個特定的頁面中。謝謝。 – James 2012-03-10 19:12:52

0

string更換爲vStr並稍作修改。

試試這個方法: -

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

忘了提及我已經嘗試過(當然不同的變量),沒有運氣。無論如何,試過它,但仍然是同樣的事情。 – James 2012-03-08 15:35:29

+0

@James:仍有相同的錯誤消息或不同的消息 – 2012-03-08 15:39:12

+0

相同的錯誤消息。 – James 2012-03-08 15:50:38

0

爲了解決這個問題,你需要首先檢查字符串中有炭,做..

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 

和..

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

這應該解決您的Type Mismatch問題。不要問我爲什麼,它只是起作用。

3

我同意安東尼的意見,你應該在ASP頁面的頂部使用Option Explicit。

我懷疑的原因是誤或缺失包括文件

我可以通過改變它下面,我要麼刪除

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

或malform調用的代碼複製這

<!-#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>