Home All Groups Group Topic Archive Search About

For Next Loop - Manual Might Be Wrong

Author
1 Sep 2006 12:31 AM
Miro
Im using VB2003 and i just pulled an example out of the book that says this:

"Note: also that you can decalre the index variable in a For Loop using the
optional AS datatype clause, as long as the index variable isnt already
declared eslewhere.  ( This is new to Visual Basic.net 2003 )

It then gives the example :

For intLoopIndex As Integer = 0 To 1
'This next line i have dummy'd down cause they use it to print an array
element so like Foo( intLoopIndex )
    Console.WriteLine("Hello")
Next intLoopIndex

It does not mention having option strict on and  option explicit on.  I have
them both on.
My simple solution is to just dim it before, cause it complaines that
intLoopIndex is not declared.

Im assuming its either because of the Option Strict and Option Explicit
and not a typo ( somehow ) in the book.

Miro

Author
1 Sep 2006 1:06 AM
iwdu15
this works fine for me...with Optin Strict on and off and Option Explicit on
and off

  For x As Integer = 0 To 5

''Do Stuff

        Next

--
-iwdu15
Author
1 Sep 2006 1:42 AM
GhostInAK
Hello Miro,

I've only tested this on VB6 and VB.Net on 2.0 framework..  Including the
indexer in your Next statement drasticly decreases performance in long-running
loops.  You certainly wont notice a degredation on low to moderate interations
(say, less than 250,000).

-Boo

Show quoteHide quote
> Im using VB2003 and i just pulled an example out of the book that says
> this:
>
> "Note: also that you can decalre the index variable in a For Loop
> using the optional AS datatype clause, as long as the index variable
> isnt already declared eslewhere.  ( This is new to Visual Basic.net
> 2003 )
>
> It then gives the example :
>
> For intLoopIndex As Integer = 0 To 1
> 'This next line i have dummy'd down cause they use it to print an
> array
> element so like Foo( intLoopIndex )
> Console.WriteLine("Hello")
> Next intLoopIndex
> It does not mention having option strict on and  option explicit on.
> I have
> them both on.
> My simple solution is to just dim it before, cause it complaines that
> intLoopIndex is not declared.
> Im assuming its either because of the Option Strict and Option
> Explicit and not a typo ( somehow ) in the book.
>
> Miro
>
Author
1 Sep 2006 2:34 AM
_AnonCoward
Show quote Hide quote
"Miro" <miron***@golden.net> wrote in message
news:OmtiD3VzGHA.4396@TK2MSFTNGP04.phx.gbl...
:
: Im using VB2003 and i just pulled an example out of the book that says
: this:
:
: "Note: also that you can decalre the index variable in a For Loop using
: the
: optional AS datatype clause, as long as the index variable isnt already
: declared eslewhere.  ( This is new to Visual Basic.net 2003 )
:
: It then gives the example :
:
: For intLoopIndex As Integer = 0 To 1
: 'This next line i have dummy'd down cause they use it to print an array
: element so like Foo( intLoopIndex )
:    Console.WriteLine("Hello")
: Next intLoopIndex
:
: It does not mention having option strict on and  option explicit on.  I
: have
: them both on.
: My simple solution is to just dim it before, cause it complaines that
: intLoopIndex is not declared.
:
: Im assuming its either because of the Option Strict and Option Explicit
: and not a typo ( somehow ) in the book.
:
: Miro


The example given is correct. The following compiles just fine in VB.net
2.0:

'----------------------------------------
Option Strict

Imports System

Public Module [module]
  Public Sub Main()

    Dim Arr(1) As String
    Arr(0) = "Hello"
    Arr(1) = "World"

    For intLoopIndex As Integer = 0 To 1
      Console.WriteLine(Arr(intLoopIndex))
    Next intLoopIndex

  End Sub
End Module
'----------------------------------------


Ralf
--
--
----------------------------------------------------------
*             ^~^                   ^~^                  *
*          _ {~ ~}                 {~ ~} _               *
*         /_``>*<                   >*<''_\              *
*        (\--_)++)                 (++(_--/)             *
----------------------------------------------------------
There are no advanced students in Aikido - there are only
competent beginners. There are no advanced techniques -
only the correct application of basic principles.
Author
1 Sep 2006 4:02 AM
Miro
Attached is a jpg with my mouse overs of the same code you have.

Maybe I have to download a version upgrade on my vb.net ?
Its an old version of 2003,
Its not a big deal, i just wanted to see if it really was possible.

I guess Ill just have to Dim   :-)

Miro


Show quoteHide quote
"_AnonCoward" <abc***@uvwxyz.com> wrote in message
news:Y_MJg.711$Md4.571@tornado.southeast.rr.com...
>
> "Miro" <miron***@golden.net> wrote in message
> news:OmtiD3VzGHA.4396@TK2MSFTNGP04.phx.gbl...
> :
> : Im using VB2003 and i just pulled an example out of the book that says
> : this:
> :
> : "Note: also that you can decalre the index variable in a For Loop using
> : the
> : optional AS datatype clause, as long as the index variable isnt already
> : declared eslewhere.  ( This is new to Visual Basic.net 2003 )
> :
> : It then gives the example :
> :
> : For intLoopIndex As Integer = 0 To 1
> : 'This next line i have dummy'd down cause they use it to print an array
> : element so like Foo( intLoopIndex )
> :    Console.WriteLine("Hello")
> : Next intLoopIndex
> :
> : It does not mention having option strict on and  option explicit on.  I
> : have
> : them both on.
> : My simple solution is to just dim it before, cause it complaines that
> : intLoopIndex is not declared.
> :
> : Im assuming its either because of the Option Strict and Option Explicit
> : and not a typo ( somehow ) in the book.
> :
> : Miro
>
>
> The example given is correct. The following compiles just fine in VB.net
> 2.0:
>
> '----------------------------------------
> Option Strict
>
> Imports System
>
> Public Module [module]
>  Public Sub Main()
>
>    Dim Arr(1) As String
>    Arr(0) = "Hello"
>    Arr(1) = "World"
>
>    For intLoopIndex As Integer = 0 To 1
>      Console.WriteLine(Arr(intLoopIndex))
>    Next intLoopIndex
>
>  End Sub
> End Module
> '----------------------------------------
>
>
> Ralf
> --
> --
> ----------------------------------------------------------
> *             ^~^                   ^~^                  *
> *          _ {~ ~}                 {~ ~} _               *
> *         /_``>*<                   >*<''_\              *
> *        (\--_)++)                 (++(_--/)             *
> ----------------------------------------------------------
> There are no advanced students in Aikido - there are only
> competent beginners. There are no advanced techniques -
> only the correct application of basic principles.
>
>

[attached file: for_next_error.JPG]
Author
1 Sep 2006 4:05 AM
Miro
And by pasting my pic in the previous post, I have just realized I am using
2002.

I should RTFS

Sorry for the post.

Miro

Show quoteHide quote
"Miro" <miron***@golden.net> wrote in message
news:uA0%23usXzGHA.4580@TK2MSFTNGP05.phx.gbl...
> Attached is a jpg with my mouse overs of the same code you have.
>
> Maybe I have to download a version upgrade on my vb.net ?
> Its an old version of 2003,
> Its not a big deal, i just wanted to see if it really was possible.
>
> I guess Ill just have to Dim   :-)
>
> Miro
>
>
> "_AnonCoward" <abc***@uvwxyz.com> wrote in message
> news:Y_MJg.711$Md4.571@tornado.southeast.rr.com...
>>
>> "Miro" <miron***@golden.net> wrote in message
>> news:OmtiD3VzGHA.4396@TK2MSFTNGP04.phx.gbl...
>> :
>> : Im using VB2003 and i just pulled an example out of the book that says
>> : this:
>> :
>> : "Note: also that you can decalre the index variable in a For Loop using
>> : the
>> : optional AS datatype clause, as long as the index variable isnt already
>> : declared eslewhere.  ( This is new to Visual Basic.net 2003 )
>> :
>> : It then gives the example :
>> :
>> : For intLoopIndex As Integer = 0 To 1
>> : 'This next line i have dummy'd down cause they use it to print an array
>> : element so like Foo( intLoopIndex )
>> :    Console.WriteLine("Hello")
>> : Next intLoopIndex
>> :
>> : It does not mention having option strict on and  option explicit on.  I
>> : have
>> : them both on.
>> : My simple solution is to just dim it before, cause it complaines that
>> : intLoopIndex is not declared.
>> :
>> : Im assuming its either because of the Option Strict and Option Explicit
>> : and not a typo ( somehow ) in the book.
>> :
>> : Miro
>>
>>
>> The example given is correct. The following compiles just fine in VB.net
>> 2.0:
>>
>> '----------------------------------------
>> Option Strict
>>
>> Imports System
>>
>> Public Module [module]
>>  Public Sub Main()
>>
>>    Dim Arr(1) As String
>>    Arr(0) = "Hello"
>>    Arr(1) = "World"
>>
>>    For intLoopIndex As Integer = 0 To 1
>>      Console.WriteLine(Arr(intLoopIndex))
>>    Next intLoopIndex
>>
>>  End Sub
>> End Module
>> '----------------------------------------
>>
>>
>> Ralf
>> --
>> --
>> ----------------------------------------------------------
>> *             ^~^                   ^~^                  *
>> *          _ {~ ~}                 {~ ~} _               *
>> *         /_``>*<                   >*<''_\              *
>> *        (\--_)++)                 (++(_--/)             *
>> ----------------------------------------------------------
>> There are no advanced students in Aikido - there are only
>> competent beginners. There are no advanced techniques -
>> only the correct application of basic principles.
>>
>>
>
>
>
Author
1 Sep 2006 12:56 PM
Jim Wooley
> And by pasting my pic in the previous post, I have just realized I am
> using 2002.

That would do it. The inline declaration wasn't allowed until 2003.  Don't
you hate answering your own questions...
Jim Wooley
http://devauthority.com/blogs/jwooley/default.aspx
Author
1 Sep 2006 1:38 PM
Miro
Geeze as soon as i Posted it I realized it.
I looked at the "about box" 3 times, and to think I didnt even notice it
even as I made the jpg.
But sure enough...once I hit send it hit me.

I was playing with VB.Express 2003 on another machine that came on a cd with
a different book,
and totally messed myself up.

Thanks for the posts everyone.
As suspected - Book is correct - and Im a Dumb Bum.

Miro

Show quoteHide quote
"Jim Wooley" <jimNOSPAMwooley@hotmail.com> wrote in message
news:24f81e8fd5158c89bbb9fbe1c7d@msnews.microsoft.com...
>> And by pasting my pic in the previous post, I have just realized I am
>> using 2002.
>
> That would do it. The inline declaration wasn't allowed until 2003.  Don't
> you hate answering your own questions...
> Jim Wooley
> http://devauthority.com/blogs/jwooley/default.aspx
>
>
Author
1 Sep 2006 4:59 PM
Smokey Grindel
VB Express is verison 2.0 aka 2005 not 2003 ;)

Show quoteHide quote
"Miro" <miron***@golden.net> wrote in message
news:OZZoyuczGHA.3440@TK2MSFTNGP06.phx.gbl...
> Geeze as soon as i Posted it I realized it.
> I looked at the "about box" 3 times, and to think I didnt even notice it
> even as I made the jpg.
> But sure enough...once I hit send it hit me.
>
> I was playing with VB.Express 2003 on another machine that came on a cd
> with a different book,
> and totally messed myself up.
>
> Thanks for the posts everyone.
> As suspected - Book is correct - and Im a Dumb Bum.
>
> Miro
>
> "Jim Wooley" <jimNOSPAMwooley@hotmail.com> wrote in message
> news:24f81e8fd5158c89bbb9fbe1c7d@msnews.microsoft.com...
>>> And by pasting my pic in the previous post, I have just realized I am
>>> using 2002.
>>
>> That would do it. The inline declaration wasn't allowed until 2003.
>> Don't you hate answering your own questions...
>> Jim Wooley
>> http://devauthority.com/blogs/jwooley/default.aspx
>>
>>
>
>
Author
1 Sep 2006 5:36 PM
Miro
No I think it would be a 2003 version.

It came with a book called:

Microsoft Visual Basic.net Reloaded  by Diane Zak,
It comes iwth a Product Key and on the cd it says 2003

( Personally I think the book isnt worth it.)  but it is a 2003 version.

I bought 3 books and the one that has helped me out the most is
Sams Teach Yourself Microsoft Visual Basic .Net 2003 in 21 Days
-for a good reference.

Ps...it has been more than 21 days ;)

Miro.


Show quoteHide quote
"Smokey Grindel" <nospam@nospam.com> wrote in message
news:ur0%237fezGHA.2516@TK2MSFTNGP06.phx.gbl...
> VB Express is verison 2.0 aka 2005 not 2003 ;)
>
> "Miro" <miron***@golden.net> wrote in message
> news:OZZoyuczGHA.3440@TK2MSFTNGP06.phx.gbl...
>> Geeze as soon as i Posted it I realized it.
>> I looked at the "about box" 3 times, and to think I didnt even notice it
>> even as I made the jpg.
>> But sure enough...once I hit send it hit me.
>>
>> I was playing with VB.Express 2003 on another machine that came on a cd
>> with a different book,
>> and totally messed myself up.
>>
>> Thanks for the posts everyone.
>> As suspected - Book is correct - and Im a Dumb Bum.
>>
>> Miro
>>
>> "Jim Wooley" <jimNOSPAMwooley@hotmail.com> wrote in message
>> news:24f81e8fd5158c89bbb9fbe1c7d@msnews.microsoft.com...
>>>> And by pasting my pic in the previous post, I have just realized I am
>>>> using 2002.
>>>
>>> That would do it. The inline declaration wasn't allowed until 2003.
>>> Don't you hate answering your own questions...
>>> Jim Wooley
>>> http://devauthority.com/blogs/jwooley/default.aspx
>>>
>>>
>>
>>
>
>
Author
1 Sep 2006 6:09 PM
GhostInAK
Hello Miro,

That may be, but Smokey is correct.. the "Express" versions of visual studio
are version 2005 and run against the 2.0 framework.  There was no "Express"
version for 2003 / 1.x framework (unless you count notepad and the .NET SDK).

-Boo

Show quoteHide quote
> No I think it would be a 2003 version.
>
> It came with a book called:
>
> Microsoft Visual Basic.net Reloaded  by Diane Zak, It comes iwth a
> Product Key and on the cd it says 2003
>
> ( Personally I think the book isnt worth it.)  but it is a 2003
> version.
>
> I bought 3 books and the one that has helped me out the most is Sams
> Teach Yourself Microsoft Visual Basic .Net 2003 in 21 Days -for a good
> reference.
>
> Ps...it has been more than 21 days ;)
>
> Miro.
>
> "Smokey Grindel" <nospam@nospam.com> wrote in message
> news:ur0%237fezGHA.2516@TK2MSFTNGP06.phx.gbl...
>
>> VB Express is verison 2.0 aka 2005 not 2003 ;)
>>
>> "Miro" <miron***@golden.net> wrote in message
>> news:OZZoyuczGHA.3440@TK2MSFTNGP06.phx.gbl...
>>
>>> Geeze as soon as i Posted it I realized it.
>>> I looked at the "about box" 3 times, and to think I didnt even
>>> notice it
>>> even as I made the jpg.
>>> But sure enough...once I hit send it hit me.
>>> I was playing with VB.Express 2003 on another machine that came on a
>>> cd
>>> with a different book,
>>> and totally messed myself up.
>>> Thanks for the posts everyone.
>>> As suspected - Book is correct - and Im a Dumb Bum.
>>> Miro
>>>
>>> "Jim Wooley" <jimNOSPAMwooley@hotmail.com> wrote in message
>>> news:24f81e8fd5158c89bbb9fbe1c7d@msnews.microsoft.com...
>>>
>>>>> And by pasting my pic in the previous post, I have just realized I
>>>>> am using 2002.
>>>>>
>>>> That would do it. The inline declaration wasn't allowed until 2003.
>>>> Don't you hate answering your own questions...
>>>> Jim Wooley
>>>> http://devauthority.com/blogs/jwooley/default.aspx
Author
1 Sep 2006 4:14 AM
Tom Shelton
Miro wrote:
Show quoteHide quote
> Im using VB2003 and i just pulled an example out of the book that says this:
>
> "Note: also that you can decalre the index variable in a For Loop using the
> optional AS datatype clause, as long as the index variable isnt already
> declared eslewhere.  ( This is new to Visual Basic.net 2003 )
>
> It then gives the example :
>
> For intLoopIndex As Integer = 0 To 1
> 'This next line i have dummy'd down cause they use it to print an array
> element so like Foo( intLoopIndex )
>     Console.WriteLine("Hello")
> Next intLoopIndex
>

VB.NET 2003
Option Strict On
Option Explicit On

Imports System

Module Module1

    Sub Main()
        For i As Integer = 0 To 10
            Console.WriteLine(i)
        Next
    End Sub

End Module

Works just peachy...  Now, it would be an error if you tried to access
i out side of the for loop.

--
Tom Shelton
Author
1 Sep 2006 10:37 AM
Herfried K. Wagner [MVP]
Show quote Hide quote
"Miro" <miron***@golden.net> schrieb:
> Im using VB2003 and i just pulled an example out of the book that says
> this:
>
> "Note: also that you can decalre the index variable in a For Loop using
> the optional AS datatype clause, as long as the index variable isnt
> already declared eslewhere.  ( This is new to Visual Basic.net 2003 )
>
> It then gives the example :
>
> For intLoopIndex As Integer = 0 To 1
> 'This next line i have dummy'd down cause they use it to print an array
> element so like Foo( intLoopIndex )
>    Console.WriteLine("Hello")
> Next intLoopIndex
>
> It does not mention having option strict on and  option explicit on.  I
> have them both on.
> My simple solution is to just dim it before, cause it complaines that
> intLoopIndex is not declared.

Are you sure you are using VS.NET/VB.NET 2003 or newer?  The inline syntax
is not supported by previous versions of Visual Basic.

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