Marc said:
Hi All,
The newbie strikes back,
I have downloaded several examples that contains that syntax :
For i as integer = 0 to treeview.nodes.count - 1
Why my Vs 2002 (7.0) will NOT compile as per: "Name i is not declared"?
The ability to declare loop variables 'in line' in this way was one of
only two substantive changes to the VB *language* between 2002 (7.0)
and 2003 (7.1):
What's New in Visual Basic .NET 2003
Visual Basic .NET 2003 has added functionality that simplifies bit
manipulation and loop variable declaration.
Bit Shift Operators
Visual Basic .NET now supports arithmetic left and right shift
operations on integral data types (Byte, Short, Integer, and Long).
Arithmetic shifts are not circular, which means the bits shifted off
one end of the result are not reintroduced at the other end. The
corresponding assignment operators are provided as well.
Loop Variable Declaration
Visual Basic .NET now allows you to declare a loop variable as part of
a For or For Each loop. You can include an As clause for the variable
in the For or For Each statement, provided no variable of that name has
been declared outside the loop. The scope of a loop variable declared
in this manner is the loop itself.
If you regularly have to use both versions, you may want to 'avoid
learning' the new loop variable syntax (the bit shift operators are
much less commonly encountered). The only accompanying *Framework*
change that catches me out is the addition of DataReader.HasRows.