Thursday, May 17, 2007

Microsoft VBScript runtime error '800a000d' Type mismatch: 'objRegExp.Replace'

As you can see, the article title describes the error of VBScript runtime. Yes, that's right. This is the runtime error when i'm using classic ASP RegEx function. So, why we get this error ?

Microsoft VBScript runtime error '800a000d'
Type mismatch: 'objRegExp.Replace'

Don't worry, not all error is caused by our mistake on programming code. Sometimes the mistake are come from the NULL value from the database. So, you need to make sure that the value returned from the database is NOT NULL.

Below is the sample of classic ASP RegEx code :

Function stripHTML(strHTML)

'Strips the HTML tags from strHTML
Dim objRegExp, strOutput

'Ensure that strHTML contains something
If Len(strHTML) = 0 Then
stripHTML = strHTML
Exit Function
End If

Set objRegExp = New Regexp

objRegExp.IgnoreCase = True
objRegExp.Global = True
objRegExp.Pattern = "<(.|\n)+?>"

'Replace all HTML tag matches with the empty string
strOutput = objRegExp.Replace(strHTML, " ")

'Replace all <> with < and >
strOutput = Replace(strOutput, "<", "<")
strOutput = Replace(strOutput, ">", ">")

stripHTML = strOutput 'Return the value of strOutput

Set objRegExp = Nothing

End Function