Re: [VB5) Faster way to read a text file?
- From: DanS <t.h.i.s.n.t.h.a.t@xxxxxxxxxxxxxxxxxxxxx>
- Date: Sun, 19 Aug 2007 16:50:01 -0500
"Ralph" <nt_consulting64@xxxxxxxxx> wrote in
news:Om#04iq4HHA.748@xxxxxxxxxxxxxxxxxxxx:
"DanS" <t.h.i.s.n.t.h.a.t@xxxxxxxxxxxxxxxxxxxxx> wrote in message
news:Xns9991B0547FE29thisnthatadelphianet@xxxxxxxxxxxxxxxxx
"Robert Morley" <rmorley@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in
news:#zAcOcV4HHA.1484@xxxxxxxxxxxxxxxxxxxx:
If anybody's curious, there's a very good wiki article on the topic
at http://en.wikipedia.org/wiki/Structured_programming. Obviously,
I would be a proponent of the Dijkstra model (though I make
exceptions for raising error conditions with "proper" use of On
Error and/or Error.Raise in VB). Most programmers these days have
moved on to the second methodology highlighted at the top of the
article, a model that permits the use of things like Exit For/Exit
Do (or Break, etc. in C/Pascal/Delphi).
What can I say? I became an old curmudgeon, set in my ways, at a
very young age. :)
I use Exit For semi-often, but only in one circumstance.
I've got an array that I am searching something for. If that array is
a large array, when I do find the value I'm looking for, I Exit For
there.
On a 1000 element array, why bother letting the loop run full if you
found the value in element number 20.
I (try) tend to think more in terms of CPU ticks.
Well, they aren't really suggesting that one does let the "loop run
full". The idea of structure in this case is the loop only exits at
the end of the the loop.
In your case, they would probably suggest an IsFound flag - and
perhaps making it the conditional of the loop. Which makes some sense.
After all, that is *really* what the loop is doing - "looking for
something". You're only going through an array because that is where
it might be found. <g>
-ralph
This is true. But, there is one more plus to it. (Note: Extremely
simplified explanation)....
Dim x as long
For x = 1 to 1000
If array(x)="String" then
Exit For
End If
Next
If x < 1001 then
' X now holds the element location that I was looking for
' Do whatever here
End IF
I could dim another variable that will hold the value of x, and replace
the Exit For with var = X, but why dim another variable when I already
have X equal to what I need.
Incidentally, I do sometimes use a boolean flag, but that's only when I'm
checking for existance, not when I need to reference the element later on
in code. Of course, if it's found. I always Exit For there anyway.
Again though, to each his own.
DanS
.
- References:
- [VB5) Faster way to read a text file?
- From: Gilles Ganault
- Re: [VB5) Faster way to read a text file?
- From: Schmidt
- Re: [VB5) Faster way to read a text file?
- From: Schmidt
- Re: [VB5) Faster way to read a text file?
- From: Randy Birch
- Re: [VB5) Faster way to read a text file?
- From: Robert Morley
- Re: [VB5) Faster way to read a text file?
- From: DanS
- Re: [VB5) Faster way to read a text file?
- From: Robert Morley
- Re: [VB5) Faster way to read a text file?
- From: DanS
- Re: [VB5) Faster way to read a text file?
- From: Robert Morley
- Re: [VB5) Faster way to read a text file?
- From: DanS
- Re: [VB5) Faster way to read a text file?
- From: Ralph
- [VB5) Faster way to read a text file?
- Prev by Date: Re: Accessing Exchange Server (on LAN)
- Next by Date: Re: [VB5) Faster way to read a text file?
- Previous by thread: Re: [VB5) Faster way to read a text file?
- Next by thread: Re: [VB5) Faster way to read a text file?
- Index(es):
Relevant Pages
|