Asp-Classic
經典 ASP:我不應該收到類型不匹配錯誤
我有一個將 HTML 編碼的文本轉換回 HTML 的功能。它正常工作,但由於某種原因,我今天嘗試在某些文本上使用它,並收到以下錯誤:
Microsoft VBScript runtime error '800a000d' Type mismatch: 'UnChkString' /manage/solutions_delete.asp, line 22我正在使用此功能的線路是:
<%= UnChkString(solution_desc) %>
solution_desc變數是:<p>Here is a description of what this solution is all about.</p>數據庫從中提取的
solution_desc欄位是文本欄位。我的 UnChkString 函式是:
Function UnChkString(string) UnChkString = Replace(string,"[%]","%") UnChkString = HTMLDecode(UnChkString) End FunctionHTMLDecode 函式是:
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(CStr(solution_desc)) %>沒有運氣。
有時最好只是非常仔細地重新閱讀錯誤。考慮這塊 VBS:
DoStuff("Hello World")由於
DoStuff沒有定義,也沒有Option Explicit我得到:錯誤:類型不匹配:‘DoStuff’
你的錯誤是:
Type mismatch: 'UnChkString'。它不抱怨傳遞的參數,而是抱怨UnChkString自己。我的猜測是你犯了最基本的 VBScript 程式錯誤,你沒有Option Explicit在你的程式碼頂部。這是必須的。由於到目前為止您發布的程式碼不清楚的原因,
<%= UnChkString(solution_desc) %>正在執行腳本引擎的程式碼沒有功能UnChkString,因此您看到的錯誤。我懷疑包含Option Explicit將揭示問題(以及迫使您使用Dim所有變數)。
我同意 Anthony 的觀點,即您應該在 ASP 頁面頂部使用 Option Explicit。
我懷疑原因是包含文件失去或格式錯誤
我可以用下面的程式碼複製它,我要麼刪除
<!--#include file="include-functions.asp"-->或將呼叫更改為
<!-#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>