Home All Groups Group Topic Archive Search About

Syntax not accepted on my version of VS why ?.

Author
26 Jan 2006 5:46 AM
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.

Author
26 Jan 2006 6:00 AM
Jay B. Harlow [MVP - Outlook]
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


Show quoteHide quote
"Marc R." <Nospam@NewgroupsONLY.com> wrote in message
news:ulXPrvjIGHA.964@tk2msftngp13.phx.gbl...
|
| 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.
|
|
Author
26 Jan 2006 6:31 AM
Cor Ligthert [MVP]
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
Author
26 Jan 2006 10:11 AM
Larry Lard
Marc R. wrote:
> 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.


--
Larry Lard
Replies to group please
Author
26 Jan 2006 11:14 AM
Herfried K. Wagner [MVP]
"Marc R." <Nospam@NewgroupsONLY.com> schrieb:
> 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
///

--
M S   Herfried K. Wagner
M V P  <URL:http://dotnet.mvps.org/>
V B   <URL:http://classicvb.org/petition/>
Author
27 Jan 2006 3:34 AM
Marc R.
is there an easy way to upgrade  to 7.1 ?



Show quoteHide quote
"Herfried K. Wagner [MVP]" <hirf-spam-me-here@gmx.at> wrote in message
news:ODhwlmmIGHA.1032@TK2MSFTNGP11.phx.gbl...
> "Marc R." <Nospam@NewgroupsONLY.com> schrieb:
>> 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
> ///
>
> --
> M S   Herfried K. Wagner
> M V P  <URL:http://dotnet.mvps.org/>
> V B   <URL:http://classicvb.org/petition/>
Author
27 Jan 2006 10:55 AM
Armin Zingler
"Marc R." <Nospam@NewgroupsONLY.com> schrieb
> is there an easy way to upgrade  to 7.1 ?

It was in 2003, when it came out ($20). You're a little late. Now version
2005 is out.


Armin