Main Menu

HOME

.Net
ASP
Assembly
C
C++
Delphi
HTML
Java
JavaScript
MySQL
PC interface
Powershell
Perl
PHP
VBScript
Visual Basic
XML

Make money selling software. Check this out here

Hosted clickbank mall. Check this out here




   Misc

   Amazon

   Links

    


For Loops
 

 

The For loop is probably the most popular loop statement in Visual Basic , here is the syntax of the For loop.

For index = start To end [Step step]
[ Statements ]
[ Exit For ]
Next [index]

The For is the keyword you use to start the loop.
Index is a user defined numeric variable that the loop uses as a counter .
start is the number from which the loop starts from .
To is the keyword which separates the start and end numbers .
end is the number at which the loop stops .
Step is an optional keyword indicating the loop should step .
step is the size of increment / decrement the step should have (this can be a negative number)
Next is the keyword that completes the loop .
index is used to identify which index is updated by the Next keyword .

Here are some general points about For loops that I have read in books that you may want to use .

  • The index value is usual called something clear like intCounter .
  • The index after the Next is optional but helps reading of your code.
  • Likewise if your Step value is 1 you can omit the Step 1 from the end of your because the default value is 1 , but it is best kept for clarity .

Lets look at some samples , none of these require any extra controls (note set the AutoRedraw property to True) . Enter the following code in the Form Load event.

example 2

example 3

These examples will give you a general idea of the For loop  


 

 

 

 




   Sponsors
 

   Software
500 Java Tips E-book
PHP editor
PERL editor
Beginning Java
Beginning Visual Basic
Learn VB.net
Learn VB 6
VB and databases
ASP image library
C++ builder programming
C++ fundamentals

   Source Code
factorial function(VB)
Create a database(VB)
opens find files dialog box(VB)
text example with delays(Darkbasic)
str_replace example(php)
Send an email(ASP)
Slashdot feed(PHP)
show all files in a directory(VB.net)

    




Copyright © 2003 by programmershelp.co.uk