Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP 3 Classic ASP Active Server Pages 3.0 > Classic ASP Databases
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
Classic ASP Databases Discuss using ASP 3 to work with data in databases, including ASP Database Setup issues from the old P2P forum on this specific subtopic. See also the book forum Beginning ASP.NET Databases for questions specific to that book. NOT for ASP.NET 1.0, 1.1, or 2.0.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Classic ASP Databases section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Display Modes
  #1 (permalink)  
Old January 13th, 2005, 02:31 AM
Friend of Wrox
 
Join Date: Jul 2004
Location: , , .
Posts: 236
Thanks: 0
Thanked 0 Times in 0 Posts
Default I have another highlighting problem.

I need the keywords highlighted and don't know how to solve this:
Code:
<% 
    OPTION EXPLICIT
    Response.Buffer = True
    Response.Expires = 0
    Dim objCon
    Dim rs
    Dim sq
    Dim sBook, sChapter, sVerse
    Dim sKeyword, sKeywordb, sKeywordc, sKeywordd, sKeyworde, sKeywordf
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title>show an individual verse</title>
</head>
<body>
<%
' prevent sql injection attacks
If Instr(Request("b"), "'") > 0 Or Request("b") = "" Then
  Response.End
ElseIf Instr(Request("c"), "'") > 0  Or Request("c") = ""Then
  Response.End
ElseIf Instr(Request("v"), "'") > 0  Or Request("v") = ""Then
  Response.End
End If
sBook = Request("b")
sChapter = Request("c")
sVerse = Request("v")
sKeyword = Request.QueryString("Keyword")
sKeywordb = Request("Keywordb")
sKeywordc = Request("Keywordc")
sKeywordd = Request("Keywordd")
sKeyworde = Request("Keyworde")
sKeywordf = Request("Keywordf")

Set objCon = Server.CreateObject("ADODB.Connection")
Set rs = Server.CreateObject("ADODB.Recordset")
If sVerse = "all" Then
    sq = "select text_data, book_title, chap, vers " & _
        "from bible " & _
        "where book='" & sBook & "' " & _
        "  and chap=" & sChapter & _
        " ORDER BY vers"
Else
    sq = "select text_data, book_title, chap, vers " & _
        "from bible " & _
        "where book='" & sBook & "' " & _
        "  and chap=" & sChapter & _
        "  and vers=" & sVerse 
End If
objCon.Open "Provider=Microsoft.Jet.OLEDB.4.0;" & _
           "Data Source=" & Server.MapPath("kjv.mdb") & ";" & _ 
           "User Id=admin;Password="
rs.Open sq, objCon
%>
<b><%=rs("book_title")%>&nbsp;&nbsp;<%=rs("chap")%></b>
<p>Searching for
<%
If Trim(sKeyword & "") <> "" Then
%>
         <b><%=sKeyword%></b>
<%
End If
If Trim(sKeywordb & "") <> "" Then
%>
          &nbsp;+&nbsp;<b><%=sKeywordb%></b>
<%
End If
If Trim(sKeywordc & "") <> "" Then
%>
          &nbsp;+&nbsp;<b><%=sKeywordc%></b>
<%
End If
If Trim(sKeywordd & "") <> "" Then
%>
          &nbsp;+&nbsp;<b><%=sKeywordd%></b>
<%
End If
If Trim(sKeyworde & "") <> "" Then
%>
          &nbsp;+&nbsp;<b><%=sKeyworde%></b>
<%
End If
If Trim(sKeywordf & "") <> "" Then
%>
          &nbsp;+&nbsp;<b><%=sKeywordf%></b>
<%
End If
%>
.</p>
<%
If rs.EOF Then
  Response.Write "verse not found: " & sBook & " " & sChapter & " verse " & sVerse
ElseIf IsNull(rs(0)) Then
  Response.Write "verse not found: " & sBook & " " & sChapter & " verse " & sVerse
Else
  Do Until rs.EOF
    Response.Write "<p>" & rs("vers") & ". " & rs("text_data") &"</p>"

    rs.MoveNext
  Loop
End If
rs.Close 
Set rs = Nothing 
objCon.Close
Set objCon = Nothing
%>
</body>
</html>
Here's the include file:
Code:
<SCRIPT LANGUAGE="VBSCRIPT" RUNAT="SERVER">
Function Highlight(strText, strFind, strBefore, strAfter)
  Dim nPos
  Dim nLen
  Dim nLenAll

  nLen = Len(strFind)
  nLenAll = nLen + Len(strBefore) + Len(strAfter) + 1

  Highlight = strText

  If nLen > 0 And Len(Highlight) > 0 Then
    nPos = InStr(1, Highlight, strFind, 1)
    Do While nPos > 0
      Highlight = Left(Highlight, nPos - 1) & _
        strBefore & Mid(Highlight, nPos, nLen) & strAfter &_
         Mid(Highlight, nPos + nLen)

      nPos = InStr(nPos + nLenAll, Highlight, strFind, 1)
    Loop
  End If
End Function
</SCRIPT>
<%
'OPTION EXPLICIT
Dim strText, strFind
strFind=sKeyword
strText=rs("text_data")
strText= Highlight(strText, strFind,"<b>", "</b>")
strFind=Keywordb
strText= Highlight(strText, strFind,"<b>", "</b>")
strFind=Keywordc
strText= Highlight(strText, strFind,"<b>", "</b>")
strFind=Keywordd
strText= Highlight(strText, strFind,"<b>", "</b>")
strFind=Keyworde
strText= Highlight(strText, strFind,"<b>", "</b>")
strFind=Keywordf
strText= Highlight(strText, strFind,"<b>", "</b>")
Response.Write strText
%>
I've only worked with the first one sKeyword with no success. I need the 6 keywords.

Learning of our true origins.

I feel sorry:

http://www.infowars.com/articles/wor...eknowledge.htm

Foreknowledge of A Natural Disaster
Washington was aware that a deadly Tidal Wave was building up in the Indian Ocean
Reply With Quote
  #2 (permalink)  
Old February 11th, 2005, 05:39 PM
Registered User
 
Join Date: Feb 2005
Location: , MD, USA.
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

[quote]Originally posted by gilgalbiblewheel
 I need the keywords highlighted and don't know how to solve this:
Code:
<% 
    OPTION EXPLICIT
    Response.Buffer = True
    Response.Expires = 0
    Dim objCon
    Dim rs
    Dim sq
    Dim sBook, sChapter, sVerse
    Dim sKeyword, sKeywordb, sKeywordc, sKeywordd, sKeyworde, sKeywordf
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title>show an individual verse</title>
</head>
<body>
<%
' prevent sql injection attacks
If Instr(Request("b"), "'") > 0 Or Request("b") = "" Then
  Response.End
ElseIf Instr(Request("c"), "'") > 0  Or Request("c") = ""Then
  Response.End
ElseIf Instr(Request("v"), "'") > 0  Or Request("v") = ""Then
  Response.End
End If
sBook = Request("b")
sChapter = Request("c")
sVerse = Request("v")
sKeyword = Request.QueryString("Keyword")
sKeywordb = Request("Keywordb")
sKeywordc = Request("Keywordc")
sKeywordd = Request("Keywordd")
sKeyworde = Request("Keyworde")
sKeywordf = Request("Keywordf")

Set objCon = Server.CreateObject("ADODB.Connection")
Set rs = Server.CreateObject("ADODB.Recordset")
If sVerse = "all" Then
    sq = "select text_data, book_title, chap, vers " & _
        "from bible " & _
        "where book='" & sBook & "' " & _
        "  and chap=" & sChapter & _
        " ORDER BY vers"
Else
    sq = "select text_data, book_title, chap, vers " & _
        "from bible " & _
        "where book='" & sBook & "' " & _
        "  and chap=" & sChapter & _
        "  and vers=" & sVerse 
End If
objCon.Open "Provider=Microsoft.Jet.OLEDB.4.0;" & _
           "Data Source=" & Server.MapPath("kjv.mdb") & ";" & _ 
           "User Id=admin;Password="
rs.Open sq, objCon
%>
<b><%=rs("book_title")%>&nbsp;&nbsp;<%=rs("chap")%></b>
<p>Searching for
<%
If Trim(sKeyword & "") <> "" Then
%>
         <b><%=sKeyword%></b>
<%
End If
If Trim(sKeywordb & "") <> "" Then
%>
          &nbsp;+&nbsp;<b><%=sKeywordb%></b>
<%
End If
If Trim(sKeywordc & "") <> "" Then
%>
          &nbsp;+&nbsp;<b><%=sKeywordc%></b>
<%
End If
If Trim(sKeywordd & "") <> "" Then
%>
          &nbsp;+&nbsp;<b><%=sKeywordd%></b>
<%
End If
If Trim(sKeyworde & "") <> "" Then
%>
          &nbsp;+&nbsp;<b><%=sKeyworde%></b>
<%
End If
If Trim(sKeywordf & "") <> "" Then
%>
          &nbsp;+&nbsp;<b><%=sKeywordf%></b>
<%
End If
%>
.</p>
<%
If rs.EOF Then
  Response.Write "verse not found: " & sBook & " " & sChapter & " verse " & sVerse
ElseIf IsNull(rs(0)) Then
  Response.Write "verse not found: " & sBook & " " & sChapter & " verse " & sVerse
Else
  Do Until rs.EOF
    Response.Write "<p>" & rs("vers") & ". " & rs("text_data") &"</p>"

    rs.MoveNext
  Loop
End If
rs.Close 
Set rs = Nothing 
objCon.Close
Set objCon = Nothing
%>
</body>
</html>
Here's the include file:
Code:
<SCRIPT LANGUAGE="VBSCRIPT" RUNAT="SERVER">
Function Highlight(strText, strFind, strBefore, strAfter)
  Dim nPos
  Dim nLen
  Dim nLenAll
  
  nLen = Len(strFind)
  nLenAll = nLen + Len(strBefore) + Len(strAfter) + 1

  Highlight = strText

  If nLen > 0 And Len(Highlight) > 0 Then
    nPos = InStr(1, Highlight, strFind, 1)
    Do While nPos > 0
      Highlight = Left(Highlight, nPos - 1) & _
        strBefore & Mid(Highlight, nPos, nLen) & strAfter &_
         Mid(Highlight, nPos + nLen)

      nPos = InStr(nPos + nLenAll, Highlight, strFind, 1)
    Loop
  End If
End Function
</SCRIPT>
<%
'OPTION EXPLICIT
Dim strText, strFind
strFind=sKeyword
strText=rs("text_data")
strText= Highlight(strText, strFind,"<b>", "</b>")
strFind=Keywordb
strText= Highlight(strText, strFind,"<b>", "</b>")
strFind=Keywordc
strText= Highlight(strText, strFind,"<b>", "</b>")
strFind=Keywordd
strText= Highlight(strText, strFind,"<b>", "</b>")
strFind=Keyworde
strText= Highlight(strText, strFind,"<b>", "</b>")
strFind=Keywordf
strText= Highlight(strText, strFind,"<b>", "</b>")
Response.Write strText
%>
I've only worked with the first one sKeyword with no success. I need the 6 keywords.


First you should use the MS Access for WEB unless you have only one user.
About “Highlight”
1 You can use function REPLACE
Dim sKeyword1, sKeyword2, sKeyword3, sKeyword4, sKeyword5, sKeyword6, AfterReplaceText
Do Until rs.EOF
AfterReplaceText = REPLACE(rs("text_data"),” ” & sKeyword1 & “ ”,”<b>”& sKeyword1 &”</b>”)
AfterReplaceText = REPLACE(AfterReplaceText,” ” & sKeyword2 & “ ”,”<b>”& sKeyword2 &”</b>”)
AfterReplaceText = REPLACE(AfterReplaceText,” ” & sKeyword3 & “ ”,”<b>”& sKeyword3 &”</b>”)
AfterReplaceText = REPLACE(AfterReplaceText,” ” & sKeyword4 & “ ”,”<b>”& sKeyword4 &”</b>”)
AfterReplaceText = REPLACE(AfterReplaceText,” ” & sKeyword5 & “ ”,”<b>”& sKeyword5 &”</b>”)
AfterReplaceText = REPLACE(AfterReplaceText,” ” & sKeyword6 & “ ”,”<b>”& sKeyword6 &”</b>”)
   Response.Write "<p>" & rs("vers") & ". " & AfterReplaceText &"</p>"
    rs.MoveNext
  Loop
End If


Reply With Quote
  #3 (permalink)  
Old July 20th, 2005, 02:02 PM
Friend of Wrox
 
Join Date: Jul 2004
Location: , , .
Posts: 236
Thanks: 0
Thanked 0 Times in 0 Posts
Default

highlighting an array of keywords
Code:
<%
strFind = Keyword '"jeSus christ joseph begat"
strText = rs("text_data")'"And Jacob begat Joseph the husband of Mary, of whom was born Jesus, who is called Christ."
response.write Highlight(strText, strFind)
%>
<SCRIPT LANGUAGE="VBSCRIPT" RUNAT="SERVER">
Function Highlight(strText, strFind)
 '// Check that at least one search term has been submitted
 If Len(strFind) < 1 Then
  '// no search term entered. Exit the function
  Highlight = "No search term entered"
  Exit Function
 End If
 
 '// define the colours to be used to highlight search results
 Dim strColors : strColors = "#FF0000" ',#008000,#0000FF
 '// and split them into an array
 Dim arrColors : arrColors = Split(strColors,",")
 
 '// split the search terms into an array
 Dim arrFind : arrFind = Split(strFind," ")
 
 '// Initialize the regular expression object to perfom the search
 Dim oRegExp, oMatches, sMatch
 Set oRegExp = New RegExp
 oRegExp.Global = True '// returns all matches to the search term
 oRegExp.IgnoreCase = True '// Case insensitive
 
 '// loop through the array of search terms to find matches
 Dim i, strHighlight
 For i = 0 to UBound(arrFind)
  oRegExp.Pattern = arrFind(i) '// sets the search pattern string
  Set oMatches = oRegExp.Execute(strText) '// performs the search 
  for each match in oMatches
  '// build the code to be used to highlight results
  strHighlight = "red'><b>" & match.value & "</b>" '" & arrColors(i) & "
  next
  '// then replace matches from the search with the above code
  strText = oRegExp.Replace(strText, strHighlight)
 Next
 '// release the RegExp object
 Set oRegExp = Nothing
 '// and return the result
 Highlight = strText
End Function
</SCRIPT>
SO I made the changes but whenever I insert the Keyword and rs("text_data")

I get this error:
Quote:
quote:
Microsoft VBScript runtime error '800a01c2'

Wrong number of arguments or invalid property assignment: 'Highlight'

/wheelofgod/highlightingz.asp, line 4
Martial Law 9/11 Rise of the Police State is now available! Visit our Martial Law movie section for complete info (click here), or order now by clicking the button below or by calling 888-253-3139
http://www.infowars.com/martial_law_911.htm
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Problem with highlighting text in a combo box Kabel69 Access 5 October 18th, 2006 08:51 AM
highlighting the text after searching shazia1 VS.NET 2002/2003 0 April 1st, 2006 03:37 PM
highlighting. Problem simplified but still there gilgalbiblewheel Classic ASP Databases 6 October 5th, 2004 08:13 AM
Highlighting in a datalist olambe Classic ASP Components 3 August 23rd, 2004 06:54 PM



All times are GMT -4. The time now is 09:04 PM.


Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.