Syntax not accepted on my version of VS why ?.

  • Thread starter Thread starter Marc R.
  • Start date Start date
M

Marc R.

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"?



Thanks to light me up on that one.



Cheers!



Marc R.
 
Marc,
| 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"?

Simple! the syntax was introduced with VS 2003 (7.1) .NET 1.1.



--
Hope this helps
Jay [MVP - Outlook]
..NET Application Architect, Enthusiast, & Evangelist
T.S. Bradley - http://www.tsbradley.net


|
| 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"?
|
|
|
| Thanks to light me up on that one.
|
|
|
| Cheers!
|
|
|
| Marc R.
|
|
 
Marc,

The syntax "For i as integer" part was not yet in the version 2002.

It has in 2002 to be
\\\
dim i as integer
For i = 0 to etc.
///

I hope this helps,

Cor
 
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.
 
Marc R. said:
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 inline variable declaration is only supported in VS.NET 2003 (VB 7.1)
and VS 2005 (VB 8.0). Instead you need a separate declaration:

\\\
Dim i As Integer
For i = 0 To ...
...
Next i
///
 
is there an easy way to upgrade to 7.1 ?



Herfried K. Wagner said:
The inline variable declaration is only supported in VS.NET 2003 (VB 7.1)
and VS 2005 (VB 8.0). Instead you need a separate declaration:

\\\
Dim i As Integer
For i = 0 To ...
...
Next i
///
 
Back
Top