Brett Barabash
BBarabash at TappeConstruction.com
Thu Aug 5 13:54:18 CDT 2004
Gustav, This thread has to end for me. My paid project work is suffering, so here's my last shot at getting my point across. > I think that Next alone is more safe as it complete eliminates these classic typo errors: >For I = 1 To 10 > For J = 1 To 10 > Next I >Next I In Access 2.0, it gives me a "Next without For" compiler error. In Access 2003, VB6 and VB.NET, it me an "Invalid Next control variable reference" compiler error. I'm reasonably sure that there are no versions of VB or VBA that allow this bug to slip past the compiler. In all cases, the COMPILER eliminates the typo error. Still no chance of introducing runtime errors by using my syntax. More safe? From those big, bad compile-time errors? Gimme a break... Next! >Would you like: > > While N < 50 > ' Do stuff > Wend N No Sam, I would not like it in a box, with a fox, on a train, or in a plane. You're repeating the same tired argument with different keywords. As I said before (about the If statements and Do loops), this loop is controlled by a CONDITION, not a counter variable. True, the condition MAY involve the value of a single variable, but what about: ' Wait 1 second While GetTickCount() - lngStartCount < 1000 DoEvents Wend So to conclude, I feel that the extra effort of including the For counter variable with the Next statement is worth the effort because: A) It allows me to tell what block a Next block belongs to, without having to scroll up to the For statement. B) In cases of nested loops, it helps me to ensure that my code is placed within the proper loop. C) Using this syntax does not increase the possibility of runtime errors, but there is a minor chance that it may reduce them (see B). D) Although they are not required by the compiler, I consider them a best practice to improve code readability. As a team developer, I accept the fact that the people maintaining my code may not possess above average code-deciphering skills like Gustav, and instead tend towards average like myself. _I_ find it easier to read and maintain, and obviously there are others who do as well, or else it would have been deprecated in the syntax overhaul of VB.NET. Conversely, I haven't heard a reasonable argument why it would make code harder to read or maintain. -----Original Message----- From: accessd-bounces at databaseadvisors.com [mailto:accessd-bounces at databaseadvisors.com] On Behalf Of Gustav Brock Sent: Thursday, August 05, 2004 11:57 AM To: Access Developers discussion and problem solving Subject: Re: [AccessD] Naming Conventions Hi Brett >> I would have been silent. > Wow! I actually found something that would silence Gustav. Gotta > make a note of that... ;-) >> So, you would prefer the syntax: >> If I = 2 Then >> ' Do stuff >> End If I > Two points here: > First of all, that's not valid VB(A) syntax, so it's pretty hard to > truly comment on what I "prefer", since I couldn't have possibly used > that construct and formulated an opinion based on experience. Right??? Of course. I was moving along the tangent of Arthur's notes about "revised" syntax on the dba-tech list. > However, this is an easy one since your example is clearly not > analogous to what I stated. > A For...Next loop corresponds to a single loop variable. If > statements, Do...While loops, etc. are tied to conditions (I = 2, > strLastName = "Jones", etc.), not variables. If I place the letter I > next to the End If, it isn't very helpful since it is the condition (I > = 2) that is the basis of the code block. You are right about the Do .. Until loop. However, I find it very analogous to For I = 1 To 50 ' Do stuff Next I Also While .. Wend doesn't use it. Would you like: While N < 50 ' Do stuff Wend N > Repeating the entire condition string at the bottom of the block would > be far too wordy and the code maintainance required would outweigh its > benefit. Certainly. But I have thought about the Next (I) syntax. Though I seldom use nested loops and - when doing so - have found it very easy to keep track of the loops (I mean: one is indented inside another which is indented inside a third etc) I think that Next alone is more safe as it complete eliminates these classic typo errors: For I = 1 To 10 For J = 1 To 10 Next I Next J or: For I = 1 To 10 For J = 1 To 10 Next I Next I Using For I = 1 To 10 For J = 1 To 10 Next Next prevents and completely eliminates these errors. And I have yet to see a code example where this could confuse a decent programmer. To cut it out: How could the nested For/For/For .. Next/Next/Next loops ever cause an error? /gustav -------------------------------------------------------------------------------------------------------------------- The information in this email may contain confidential information that is legally privileged. The information is only for the use of the intended recipient(s) named above. If you are not the intended recipient(s), you are hereby notified that any disclosure, copying, distribution, or the taking of any action in regard to the content of this email is strictly prohibited. If transmission is incorrect, unclear, or incomplete, please notify the sender immediately. The authorized recipient(s) of this information is/are prohibited from disclosing this information to any other party and is/are required to destroy the information after its stated need has been fulfilled. Any views expressed in this message are those of the individual sender, except where the sender specifies and with authority, states them to be the views of Tappe Construction Co. This footer also confirms that this email message has been scanned for the presence of computer viruses.Scanning of this message and addition of this footer is performed by SurfControl E-mail Filter software in conjunction with virus detection software.