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

    Unanswered: highlighting. Problem simplified but still there

    I'm using the code on:
    http://www.aspfree.com/c/a/ASP%20Cod...-by-Meraj-Sami

    I want to use two colors on two keywords, one in red, the second in blue.

    This is the result:
    http://n.1asphost.com/wheelofgod/highlighting.asp

    (there is a third color with a third keyword but, never mind that)

    The problem is that it's restarting the text once it has found and replaced the keyword in color.

  2. #2
    Join Date
    Nov 2003
    Location
    Christchurch, New Zealand
    Posts
    1,618
    well I tried to look at your page as an example but it failed so....

  3. #3
    Join Date
    Jul 2004
    Posts
    494
    yes the same happenned to me today. Strange.

  4. #4
    Join Date
    Nov 2003
    Location
    Christchurch, New Zealand
    Posts
    1,618
    assuming you are using the first version of the example you should be able to just do it multiple times to achieve what you want.

  5. #5
    Join Date
    Jul 2004
    Posts
    494
    here is the code:
    Code:
    <SCRIPT LANGUAGE="VBSCRIPT" RUNAT="SERVER">
    Function stringReplace(strSearchWithin,strSearchFor,two,three)
    Dim lngStartingPosition
    Dim lngFoundPosition
    Dim lngFoundtwoPosition
    Dim lngFoundthreePosition
    Dim strReplaced
    'Set the start position
        lngStartingPosition=1
        lngFoundPosition=InStr(lngStartingPosition,strSearchWithin,strSearchFor,1)
        do while lngFoundPosition > 0
            'found
            strReplaced=strReplaced & Mid(strSearchWithin,lngStartingPosition,lngFoundPosition-lngStartingPosition) & "<font color='red'>" & mid(strSearchWithin,lngFoundPosition,len(strSearchFor)) & "</font>"
            lngFoundPosition=lngFoundPosition+len(strSearchFor)
            lngFoundPosition=InStr(lngStartingPosition,strSearchWithin,strSearchFor,1)
        Loop 
        stringReplace=strReplaced & Mid(strSearchWithin,lngStartingPosition) 'catch the last one
    'Set the start position
        lngStartingPosition=1
        lngFoundtwoPosition=InStr(lngStartingPosition,strSearchWithin,two,1)
        do while lngFoundtwoPosition > 0
            'found
            strReplaced=strReplaced & Mid(strSearchWithin,lngStartingPosition,lngFoundtwoPosition-lngStartingPosition) & "<font color='blue'>" & mid(strSearchWithin,lngFoundtwoPosition,len(two)) & "</font>"
            lngStartingPosition=lngFoundtwoPosition+len(two)
            lngFoundtwoPosition=InStr(lngStartingPosition,strSearchWithin,two,1)
        Loop 
        stringReplace=strReplaced & Mid(strSearchWithin,lngStartingPosition) 'catch the last one
    
    End Function
    </SCRIPT>
    <%
    OPTION EXPLICIT
    Dim strSearchWithin,strSearchFor,two,three
    strSearchWithin="Ezra  7:1 Now after these things, in the reign of Artaxerxes king of Persia, Ezra the son of Seraiah, the son of Azariah, the son of Hilkiah, "
    strSearchFor="Ezra"
    two="Artaxerxes"
    three="king"
    Response.Write stringReplace(strSearchWithin,strSearchFor,two,three)
    %><br><br>
    <font color='red'>ezra</font> <font color='blue'>artaxerxes</font>
    <br><br>
    Original phrase:<br> 
    Ezra  7:1
    Now after these things, in the reign of Artaxerxes king of Persia, Ezra the son of Seraiah, the son of Azariah, the son of Hilkiah,
    <br><br>
    
    The problem is that it's restarting the text once it has found and replaced the keyword in color.

  6. #6
    Join Date
    Nov 2003
    Location
    Christchurch, New Zealand
    Posts
    1,618
    in your second loop you should be using the new string not the orginal string... eg
    Code:
    <SCRIPT LANGUAGE="VBSCRIPT" RUNAT="SERVER">
    Function stringReplace(strSearchWithin,strSearchFor,two,three)
    Dim lngStartingPosition
    Dim lngFoundPosition
    Dim lngFoundtwoPosition
    Dim lngFoundthreePosition
    Dim strReplaced
    'Set the start position
        lngStartingPosition=1
        lngFoundPosition=InStr(lngStartingPosition,strSearchWithin,strSearchFor,1)
        do while lngFoundPosition > 0
            'found
            strReplaced=strReplaced & Mid(strSearchWithin,lngStartingPosition,lngFoundPo  sition-lngStartingPosition) & "<font color='red'>" & mid(strSearchWithin,lngFoundPosition,len(strSearch  For)) & "</font>"
            lngFoundPosition=lngFoundPosition+len(strSearchFor  )
            lngFoundPosition=InStr(lngStartingPosition,strSear  chWithin,strSearchFor,1)
        Loop 
        tmpString=strReplaced & Mid(strSearchWithin,lngStartingPosition) 'catch the last one
        strReplaced=""
    'Set the start position
        lngStartingPosition=1
        lngFoundtwoPosition=InStr(lngStartingPosition,tmpString,two,1)
        do while lngFoundtwoPosition > 0
            'found
            strReplaced=strReplaced & Mid(tmpString,lngStartingPosition,lngFoundtw  oPosition-lngStartingPosition) & "<font color='blue'>" & mid(tmpString,lngFoundtwoPosition,len(two)) & "</font>"
            lngStartingPosition=lngFoundtwoPosition+len(two)
            lngFoundtwoPosition=InStr(lngStartingPosition,tmpString,two,1)
        Loop 
        stringReplace=strReplaced & Mid(tmpString,lngStartingPosition) 'catch the last one
    End Function
    or something very similar.

  7. #7
    Join Date
    Jul 2004
    Posts
    494
    This thing is giving me a hard time:
    Active Server Pages error 'ASP 0113'

    Script timed out

    /wheelofgod/highlight2.asp

    The maximum amount of time for a script to execute was exceeded. You can change this limit by specifying a new value for the property Server.ScriptTimeout or by changing the value in the IIS administration tools.
    My search engine loads faster than the link posted above.

  8. #8
    Join Date
    Nov 2003
    Location
    Christchurch, New Zealand
    Posts
    1,618
    yeah, what are your querying and how big is your database? It looks like you are trying to do a big query and it's not returning in time or you have set up some kind of nasty looping somewhere or something.

Posting Permissions

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