VB.NET for-next loop syntax - simple question

  • Thread starter Thread starter Jon Maz
  • Start date Start date
J

Jon Maz

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
 
Jon said:
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.
 
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
 
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
 
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
 
Cor,
FolderBrowserDialog was a framework change not a VB.NET Language change.

Remember Larry specifically stated " *language* changes "
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top