469,292 Members | 1,325 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,292 developers. It's quick & easy.

VB.NET for-next loop syntax - simple question

Hi All,

Quick one: several times in vb.net code I have got off the net there are
lines such as:

For i As Integer = 0 To 10

which, on compiling with VS2002, produce the following error:

error BC30451: Name 'i' is not declared.

One way to fix this issue is to separate the declaration into a new line:

Dim i As Integer
For i As Integer = 0 To 10

But the fact that I keep seeing this in other people's code is making me
wonder what's going on...

Any answers out there?

Cheers,

JON
Nov 21 '05 #1
8 13818

Jon Maz wrote:
Hi All,

Quick one: several times in vb.net code I have got off the net there are lines such as:

For i As Integer = 0 To 10

which, on compiling with VS2002, produce the following error:

error BC30451: Name 'i' is not declared.

One way to fix this issue is to separate the declaration into a new line:
Dim i As Integer
For i As Integer = 0 To 10

But the fact that I keep seeing this in other people's code is making me wonder what's going on...

Any answers out there?


The ability to declare loop variables in the loop statement was one of
the (very few) *language* changes in VB.Net 2003 from 2002. The only
other was the introduction of the bit shift operators << and >>.

VB.Net 2005 (as and when it emerges) will have considerably more, be
warned.

If you are writing for people who still have VB.Net 2002, you must take
care to avoid this construct and those operators.

--
Larry Lard
Replies to group please

Nov 21 '05 #2
"Jon Maz" <jo****@surfeuNOSPAM.de> wrote in news:eqCxPG3EFHA.3512
@TK2MSFTNGP10.phx.gbl:
For i As Integer = 0 To 10

But the fact that I keep seeing this in other people's code is making me
wonder what's going on...

Any answers out there?


Might be a new syntax extension in VB 2..5.
--
Chad Z. Hower (a.k.a. Kudzu) - http://www.hower.org/Kudzu/
"Programming is an art form that fights back"

Develop ASP.NET applications easier and in less time:
http://www.atozed.com/IntraWeb/
Nov 21 '05 #3
You are using Visual Studio 2002. Only in 2003 and beyond, the more compact
style of declaring for-loop (and for-each) variables in the loop header is
supported in VB.NET.

David Anton
Tangible Software Solutions Inc.
Home of the Instant C# and Instant VB .NET language converters
www.tangiblesoftwaresolutions.com

"Jon Maz" wrote:
Hi All,

Quick one: several times in vb.net code I have got off the net there are
lines such as:

For i As Integer = 0 To 10

which, on compiling with VS2002, produce the following error:

error BC30451: Name 'i' is not declared.

One way to fix this issue is to separate the declaration into a new line:

Dim i As Integer
For i As Integer = 0 To 10

But the fact that I keep seeing this in other people's code is making me
wonder what's going on...

Any answers out there?

Cheers,

JON

Nov 21 '05 #4
Larry,

Don't forget the FolderBrowserDialog which now with SP1 seems without bugs.

The wrote it nowhere however beside the more stability, the better
conversion from VB6, and the smaller deployment, one of the major
improvements for me.

Just my thought,

Cor
Nov 21 '05 #5
Cor,
FolderBrowserDialog was a framework change not a VB.NET Language change.

Remember Larry specifically stated " *language* changes "
"Cor Ligthert" <no************@planet.nl> wrote in message
news:uI**************@TK2MSFTNGP12.phx.gbl...
Larry,

Don't forget the FolderBrowserDialog which now with SP1 seems without
bugs.

The wrote it nowhere however beside the more stability, the better
conversion from VB6, and the smaller deployment, one of the major
improvements for me.

Just my thought,

Cor

Nov 21 '05 #6
Mmm, thought it must be something like that...

Presumably I could use a command-line compile with v1.1 to get round this?

Thanks,

JON
Nov 21 '05 #7
Cor,

"Cor Ligthert" <no************@planet.nl> schrieb:
Don't forget the FolderBrowserDialog which now with SP1 seems without
bugs.


.... that's not a language change :-).

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

Nov 21 '05 #8
Herfried and Jay,

You both are right

LOL.

Cor
Nov 21 '05 #9

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by Xerxes | last post: by
4 posts views Thread by Craig Bailey | last post: by
reply views Thread by Verizon | last post: by
reply views Thread by Robert Freund | last post: by
33 posts views Thread by Frank | last post: by
reply views Thread by Mr.Bogi | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by suresh191 | last post: by
1 post views Thread by Geralt96 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.