Re: [VB5) Faster way to read a text file?

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance



"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


.



Relevant Pages

  • Re: [VB5) Faster way to read a text file?
    ... for raising error conditions with "proper" use of On Error and/or ... I use Exit For semi-often, ... I've got an array that I am searching something for. ... they aren't really suggesting that one does let the "loop run full". ...
    (microsoft.public.vb.general.discussion)
  • Re: [VB5) Faster way to read a text file?
    ... What you've described is a very common usage of Exit For. ... would normally structure that with the equivalent While loop: ... While (Not blnFound) And ... I've got an array that I am searching something for. ...
    (microsoft.public.vb.general.discussion)
  • Re: COBOL myth busted, index versus subscript (MF on HP)
    ... curious about an array without an index defined, ... So, Question, what is exit perform cycle? ... When I first ran the test, the null loop was empty. ...
    (comp.lang.cobol)
  • Re: compare 2 recordsets
    ... This made me think that maybe a double loop could be faster as you ... point and do exit do or exit loop when it has past the value. ... Another thing to try is using GetRows to put the rsParentNode data into an array - looping through an array is much quicker than looping through a recordset ...
    (microsoft.public.data.ado)
  • Re: [VB5) Faster way to read a text file?
    ... would be a proponent of the Dijkstra model (though I make exceptions ... for raising error conditions with "proper" use of On Error and/or ... I use Exit For semi-often, ... I've got an array that I am searching something for. ...
    (microsoft.public.vb.general.discussion)