Forum Moderators: open

Message Too Old, No Replies

ASP & instr & loops

         

placbill

7:18 am on Jan 14, 2004 (gmt 0)

10+ Year Member



newbie requires assistance.

working with instr function in an ASP page.
code functions and finds all urls 0-100 per page.
The problem is that either it crashes or it goes into an infinate loop. What have i missed that it doesn'break out of the loop properly.

' Actually Sends the request and returns the data:
xml.Send

' buffers response to string var

strBuffer=xml.ResponseText

'sets counters and loop length.

strLen = Len(strBuffer)
curserloc = 1
count = 0
do while curserloc < strLen
count = count + 1
'finds string
strstart = instr(curserloc,strBuffer,"PgIenyDetail.jsp?hiddenNotary=" )
if strstart then text = mid(strBuffer,strstart,38)
curserloc = strstart + 38
Response.Write text & " " & curserloc & " " & strLen & " " & count & "<BR>"

loop

IanTurner

8:23 am on Jan 14, 2004 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



You are resetting strstart inside the loop - so that curserloc never increments.

placbill

3:09 am on Jan 15, 2004 (gmt 0)

10+ Year Member



Thank you, IanTurner for your response on the matter but your explination has left me with some thoughts. I have to reset strstart in the loop because for every instance of the search string strstart returns the starting position of the string.

It was trying to figure out how to stop the looping process. the only working approach I have got working is the following:

while strstart
count = count + 1
strstart = instr(curserloc,strBuffer,"PgIenyDetail.jsp?hiddenNotary=" )
if strstart then
text = mid(strBuffer,strstart,38)
Names(count) = text
Response.Write Base & Names(count) & " " & curserloc & " " & strstart & " " & count & "<BR>"
curserloc = strstart + 38

else
strstart =0
Response.Write " " & curserloc & " " & strstart & " " & count & "<BR>"
end if
wend

Although, something in that lacks elagance and why didn't it return a null or an out of bounds error when I tried to go beyond the string length. Why did it restart at the begining and start to research.

Thank you,
placbill