what's wrong with this script?

P

PeterB

Hi!

I have been looking at a script for downloading files from aspfaw.com:
http://www.aspfaq.com/show.asp?id=2161

It's the script for larger downloads (second larger code-block).

Here's a snippet:

Response.AddHeader "Content-Length", iSz

For i = 1 To iSz \ chunk
If Not Response.IsClientConnected Then Exit For
Response.BinaryWrite adoStream.Read(chunk)
Next


What does "For" stand for that is after "Then Exit" (Then Exit For)? Isn't
End If missing in that statement?

thanks,

Peter
 
P

Phill. W

PeterB said:
For i = 1 To iSz \ chunk
If Not Response.IsClientConnected Then Exit For
Response.BinaryWrite adoStream.Read(chunk)
Next

What does "For" stand for that is after "Then Exit" (Then Exit For)?

"For" stands for the [innermost] "For" Loop within which it appears.
"Exit For" instructs VB to "drop out" of a loop, continuing with the
next statement after the corresponding "Next".
(It's a nice[r] way of doing a Goto out of a loop).
Isn't End If missing in that statement?

No. This is the single-line form of If, which does not require a
matching End If, and, as you've discovered, it's damnably confusing.
I would /much/ prefer to see :

For i = 1 To iSz \ chunk
If Not Response.IsClientConnected Then
Exit For
End If

Response.BinaryWrite adoStream.Read(chunk)
Next

I thought about this as well :

For i = 1 To iSz \ chunk
If Response.IsClientConnected Then
Response.BinaryWrite adoStream.Read(chunk)
End If
Next

which /looks/ cleaner still, but if the loop executes a *lot* of
times and the client gets disconnected on one of the early iterations,
you're wasting a whole load of processor time doing all the /other/
iterations unnecessarily.

HTH,
Phill W.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,995
Messages
2,570,225
Members
46,815
Latest member
treekmostly22

Latest Threads

Top