Results 1 to 2 of 2
  1. #1
    Join Date
    Jul 2004
    Posts
    494

    Unanswered: how to highlight in three colours? have code but

    There is something wrong in this. I couldn't figure it out.

    I have three: Keyword, Keywordb, Keywordc
    I had inserted: strSearchFor, two, three (same function)

    Code:
    <SCRIPT LANGUAGE="VBSCRIPT" RUNAT="SERVER">
    Function stringReplace(strSearchWithin,strSearchFor,two,three)
    Dim lngStartingPosition
    Dim lngFoundPosition
    Dim strReplaced
    'Set the start position
    lngStartingPosition=1
    lngFoundPosition=InStr(lngStartingPosition,strSearchWithin,strSearchFor,1)
    lngFoundPosition=InStr(lngStartingPosition,strSearchWithin,two,1)
    lngFoundPosition=InStr(lngStartingPosition,strSearchWithin,three,1)
    do while lngFoundPosition > 0
    'found
    strReplaced=strReplaced & Mid(strSearchWithin,lngStartingPosition,lngFoundPosition-lngStartingPosition) & "<font color='red'>" & "<b>" & mid(strSearchWithin,lngFoundPosition,len(strSearchFor)) & "</b>" & "</font>"
    
    strReplaced=strReplaced & Mid(strSearchWithin,lngStartingPosition,lngFoundPosition-lngStartingPosition) & "<font color='blue'>" & "<b>" & mid(strSearchWithin,lngFoundPosition,len(two)) & "</b>" & "</font>"
    
    strReplaced=strReplaced & Mid(strSearchWithin,lngStartingPosition,lngFoundPosition-lngStartingPosition) & "<font color='green'>" & "<b>" & mid(strSearchWithin,lngFoundPosition,len(three)) & "</b>" & "</font>"
    
    
    lngStartingPosition=lngFoundPosition+len(strSearchFor)
    lngStartingPosition=lngFoundPosition+len(two)
    lngStartingPosition=lngFoundPosition+len(three)
    
    
    lngFoundPosition=InStr(lngStartingPosition,strSearchWithin,strSearchFor,1)
    lngFoundPosition=InStr(lngStartingPosition,strSearchWithin,two,1)
    lngFoundPosition=InStr(lngStartingPosition,strSearchWithin,three,1)
    Loop
    stringReplace=strReplaced & Mid(strSearchWithin,lngStartingPosition) 'catch the last one
    End Function
    </SCRIPT>
    
    <%
    
    strSearchWithin=RS("res_text_data")
    strSearchFor=Keyword
    two=Keywordb
    three=Keywordc
    Response.Write stringReplace(strSearchWithin,strSearchFor,two,three)
    %>

  2. #2
    Join Date
    Jul 2004
    Posts
    494

    more

    what I'm getting is a repetition of "res_text_data" three times after a word is highlighted:

    Now after these things, in the reign of Artaxerxes king[u]Now after these things[u], in the reign of Artaxerxes king of PeNow after these things, in the reign of Artaxerxes king of Persia, Ezra the son of Seraiah, the son of Azariah, the son of Hilkiah,

    I had forgotten to include the Dim in the previous posting:
    Code:
    <%Dim strSearchWithin,strSearchFor,two,three%>
    It would also help to mention you that the three keywords are:
    Ezra, Artaxerxes, king. So when you see those words there is a repetition of the text.

    There is a confusion in the colors, for instance one which is supposed to be red is in blue...

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •