Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP General > what's wrong with this script?

Reply
Thread Tools

what's wrong with this script?

 
 
PeterB
Guest
Posts: n/a
 
      02-04-2005
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


 
Reply With Quote
 
 
 
 
Phill. W
Guest
Posts: n/a
 
      02-04-2005
"PeterB" <(E-Mail Removed)> wrote in message
news:%(E-Mail Removed)...
> 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.


 
Reply With Quote
 
 
 
Reply

Thread Tools

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 Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Have I bought wrong product? enquirer Wireless Networking 2 06-10-2005 10:59 PM
Zero Config keeps connecting to the wrong AP =?Utf-8?B?ZGdyaWZmaXRo?= Wireless Networking 2 03-04-2005 05:52 PM
Is XML Doc wrong or is Schema wrong? (or both) Matthew XML 7 01-07-2005 10:05 PM
wrong connection status Peter Welk Wireless Networking 0 12-22-2004 03:26 PM
XP SP2 Wrong IP on connection D Wells Wireless Networking 3 12-09-2004 03:35 AM



Advertisments