If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > ASP > highlighting. Problem simplified but still there

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 10-03-04, 16:16
gilgalbiblewhee gilgalbiblewhee is offline
Registered User
 
Join Date: Jul 2004
Posts: 494
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.
Reply With Quote
  #2 (permalink)  
Old 10-04-04, 22:29
rokslide rokslide is offline
Registered User
 
Join Date: Nov 2003
Location: Christchurch, New Zealand
Posts: 1,617
well I tried to look at your page as an example but it failed so....
Reply With Quote
  #3 (permalink)  
Old 10-04-04, 23:31
gilgalbiblewhee gilgalbiblewhee is offline
Registered User
 
Join Date: Jul 2004
Posts: 494
yes the same happenned to me today. Strange.
Reply With Quote
  #4 (permalink)  
Old 10-04-04, 23:34
rokslide rokslide is offline
Registered User
 
Join Date: Nov 2003
Location: Christchurch, New Zealand
Posts: 1,617
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.
Reply With Quote
  #5 (permalink)  
Old 10-04-04, 23:42
gilgalbiblewhee gilgalbiblewhee is offline
Registered User
 
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.
Reply With Quote
  #6 (permalink)  
Old 10-04-04, 23:52
rokslide rokslide is offline
Registered User
 
Join Date: Nov 2003
Location: Christchurch, New Zealand
Posts: 1,617
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.
Reply With Quote
  #7 (permalink)  
Old 10-05-04, 14:24
gilgalbiblewhee gilgalbiblewhee is offline
Registered User
 
Join Date: Jul 2004
Posts: 494
This thing is giving me a hard time:
Quote:
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.
Reply With Quote
  #8 (permalink)  
Old 10-05-04, 19:40
rokslide rokslide is offline
Registered User
 
Join Date: Nov 2003
Location: Christchurch, New Zealand
Posts: 1,617
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.
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On