2012-03-08 19 views
7

Ho una funzione per trasformare il testo con codice HTML in HTML. E le grandi opere in genere, ma per qualche ragione, cerco di usarlo su un testo di oggi, e ottenere il seguente errore:ASP classico: sto ricevendo un errore di mancata corrispondenza di tipo quando non dovrei

Microsoft VBScript runtime error '800a000d' 

Type mismatch: 'UnChkString' 

/manage/solutions_delete.asp, line 22 

La linea che sto usando questa funzione è:

<%= UnChkString(solution_desc) %> 

la variabile è solution_desc:

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

il campo del database sta tirando il solution_desc da è un campo di testo.

La mia funzione è UnChkString:

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

La funzione 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 

EDIT

Ho anche provato:

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

senza fortuna.

+0

Qual è la linea 22? – bfavaretto

+0

@bfavaretto '<% = UnChkString (solution_desc)%>' – James

+0

Forse stai ottenendo 'NULL' dal DB? L'errore si verifica con la stringa di esempio che hai postato? – bfavaretto

risposta

7

volte del suo meglio per appena riletto l'errore con molta attenzione. Considerate questo pezzo di VBS:

DoStuff("Hello World") 

Dal DoStuff non è definito né v'è un Option Explicit ottengo:

Error: Type mismatch: 'DoStuff'

Il tuo errore è: Type mismatch: 'UnChkString'. Non si lamenta del fatto che il parametro è passato lamentandosi di UnChkString stesso. La mia ipotesi è che tu abbia commesso il più elementare dei goofs di programmazione VBScript, non hai uno Option Explicit nella parte superiore del tuo codice. Questo è un must.

Per motivi non chiari, il codice che hai inviato fino ad ora il codice nel punto in cui è stato eseguito <%= UnChkString(solution_desc) %>, il motore di script non ha una funzione UnChkString, quindi l'errore che stai vedendo. Sospetto che l'inclusione di Option Explicit rivelerà il problema (oltre a costringerti a Dim tutte le tue variabili).

+0

Ho iniziato a rispondere dicendo che avrei voluto che fosse così semplice, ma che lo script delle funzioni sia stato caricato automaticamente in ogni pagina, ma poi controllato comunque. Questa era la ragione. Lo script delle mie funzioni non era incluso in questa particolare pagina. Grazie. – James

0

Sostituire string in vStr e leggermente modificato.

provare in questo modo: -

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

Ho dimenticato di averlo già provato anch'io (variabile diversa, ovviamente) senza fortuna. Provato di nuovo lo stesso, ma sempre la stessa cosa. – James

+0

@James: Ancora lo stesso messaggio di errore o msg diverso –

+0

Stesso messaggio di errore. – James

0

Al fine di risolvere il problema, è necessario verificare prima se la stringa ha il carattere in esso, fare questo ..

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 

E ..

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

Questo dovrebbe risolvere il tuo Type Mismatch problema. Non chiedermi perché, funziona e basta.

3

Sono d'accordo con Anthony secondo cui dovresti utilizzare Option Explicit nella parte superiore delle pagine ASP.

Ho il sospetto che la causa è un mancante o malformati include file

posso replicare questo con il codice qui sotto dove ho rimuovere

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

o deformano la chiamata cambiando a

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