Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Highlght search term but ignore HTML markup

Status
Not open for further replies.

Floodster39

IS-IT--Management
Aug 15, 2012
1
0
0
GB
thread333-863709

I've been trying to implement the code in the above thread but I'm getting an error when trying to call it.
The error is "Wrong number of arguments or invalid property assignment: 'HighLight'"

The function I've copied is below
Code:
Function HighLight(TextIn, TextToHighlight, bAll)
dim i,WordArr,TextOut,bHL,bHL2,bNoHL

const HLStyle = "<span style=""color:red;font-weight:bold;background-color:#FFFFCC"">"
const HLStyle2 = "<span style=""color:blue;font-weight:bold;background-color:silver"">"

WordArr = Split(TextIn," ")
for i = 0 to Ubound(WordArr)
	bHL = False
	bHL2 = False
	if lcase(WordArr(i)) = "<a" then bNoHL = true
   if not bNoHL then
		if WordArr(i) = TextToHighlight then bHL = True ' highlight this word 
		if PunctMarks(right(WordArr(i),1),"[.,]") then    'check for full stop or comma
			if TextToHighlight = left(WordArr(i),len(WordArr(i))-1) then bHL = True
			' if word matches ignoring the last char highlight it
		end if
		if bAll then 
			' highlight all instances
			if InStr(WordArr(i),TextToHighlight) <> 0 then bHL2 = True
		end if
    
		if bHL then
			TextOut = TextOut & " " & HLStyle & WordArr(i) & "</span>"
		elseif bHL2 then
			TextOut = TextOut & " " & HLStyle2 & WordArr(i) & "</span>"
		else
			TextOut = TextOut & " " &  WordArr(i)
		end if
	
	end if
		
		if lcase(WordArr(i)) = "</a>" then bNoHL = false

next
HighLight = TextOut
End Function

function PunctMarks(strIn, Pattern)
dim objRE
set objRE = New RegExp 
objRE.pattern = Pattern

PunctMarks = objRE.Test(strIn)

end function

I am then calling it by using the below in my page
Code:
<%=HighLight("texttosearch", "text", true)%>

Can anybody spot anything glaringly obvious??
Thanks
 
Looks ok to me; are you sure the error is occurring on the ASP line you indicated? And that the highlight function is in the same asp file, or included in that file?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top