473,385 Members | 1,861 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

For Next Loop - Manual Might Be Wrong

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
Sep 1 '06 #1
11 1511
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
Sep 1 '06 #2
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
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

Sep 1 '06 #3

"Miro" <mi******@golden.netwrote in message
news:Om**************@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.
Sep 1 '06 #4
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

"Miro" <mi******@golden.netwrote in message
news:uA****************@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" <ab****@uvwxyz.comwrote in message
news:Y_***************@tornado.southeast.rr.com...
>>
"Miro" <mi******@golden.netwrote in message
news:Om**************@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.




Sep 1 '06 #5

Miro wrote:
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

Sep 1 '06 #6
"Miro" <mi******@golden.netschrieb:
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/>

Sep 1 '06 #7
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
Sep 1 '06 #8
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" <ji*************@hotmail.comwrote in message
news:24*************************@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


Sep 1 '06 #9
VB Express is verison 2.0 aka 2005 not 2003 ;)

"Miro" <mi******@golden.netwrote in message
news:OZ**************@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" <ji*************@hotmail.comwrote in message
news:24*************************@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



Sep 1 '06 #10
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" <no****@nospam.comwrote in message
news:ur****************@TK2MSFTNGP06.phx.gbl...
VB Express is verison 2.0 aka 2005 not 2003 ;)

"Miro" <mi******@golden.netwrote in message
news:OZ**************@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" <ji*************@hotmail.comwrote in message
news:24*************************@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




Sep 1 '06 #11
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
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" <no****@nospam.comwrote in message
news:ur****************@TK2MSFTNGP06.phx.gbl...
>VB Express is verison 2.0 aka 2005 not 2003 ;)

"Miro" <mi******@golden.netwrote in message
news:OZ**************@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" <ji*************@hotmail.comwrote in message
news:24*************************@msnews.microsof t.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

Sep 1 '06 #12

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Sandman | last post by:
Ok, so I have PHP set upp to ato_prepend and auto_append files to every script I run. So if I someone surfs to /index.php, these scripts run: init.php -> set up DB connections and...
10
by: Brian Burgess | last post by:
Hi all, Is there any 'trick' anyone knows to control a For Next to pass to the next iteration in ASP VBScript? ..Similar to the 'continue' keyword of C and C++? Thanks in advance.. -BB
16
by: TheKeith | last post by:
I'm writing a script with a while loop in it. How can I get it to go slower so that it doesn't appear to happen all at once--so that it looks animated--basically. I tried the setTimeout(500) in the...
16
by: Joseph | last post by:
Environment: Linux C program (gcc), on linux kernel 2.6.16 Is there any function I can put inside a tight loop in order to make the process a little nicer. In that it will give at least the CPU...
16
by: fniles | last post by:
I am using VB.NET 2003, SQL 2000, and SqlDataAdapter. For every record in tblA where colB = 'abc', I want to update the value in colA. In VB6, using ADO I can loop thru the recordset,set the...
3
JodiPhillips
by: JodiPhillips | last post by:
Hello All, I'm trying to limit the number of attempts a user has to log into an MS Access 2003 database, but am having very little success. My current code for log in is as follows (and thanks...
3
by: Damo | last post by:
Hi, I want to create variables in a loop, each with a different name. Here is the loop i'm using: if (is_array($attribs)) { echo "Attributes : <br />"; while(list($key,$val) =...
0
by: Semajthewise | last post by:
Hi all. I'm starting on my next part of my teach myself vb program. What I am trying to do is on button click open a textfile showing the math as it would be done long hand. I started writing the...
2
ADezii
by: ADezii | last post by:
If you are executing a code segment for a fixed number of iterations, always use a For...Next Loop instead of a Do...Loop, since it is significantly faster. Each pass through a Do...Loop that...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.