473,800 Members | 2,342 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.WriteLi ne("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 1540
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.WriteLi ne("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******@golde n.netwrote in message
news:Om******** ******@TK2MSFTN GP04.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.WriteLi ne("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.WriteLi ne(Arr(intLoopI ndex))
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******@golde n.netwrote in message
news:uA******** ********@TK2MSF TNGP05.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
"_AnonCowar d" <ab****@uvwxyz. comwrote in message
news:Y_******** *******@tornado .southeast.rr.c om...
>>
"Miro" <mi******@golde n.netwrote in message
news:Om******* *******@TK2MSFT NGP04.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.WriteLi ne("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.WriteLi ne(Arr(intLoopI ndex))
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.WriteLi ne("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.WriteLi ne(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******@golde n.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.WriteLi ne("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.comwr ote in message
news:24******** *************** **@msnews.micro soft.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******@golde n.netwrote in message
news:OZ******** ******@TK2MSFTN GP06.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.comwr ote in message
news:24******** *************** **@msnews.micro soft.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

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

Similar topics

6
4030
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 stuff. Buffers output index.php -> The current page with it's layout, output is buffered. postprocess.php -> Fetches buffer, applies layout to page. Now, sometimes I want to break the execution of index.php (or whatever page that is...
10
8318
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
9916
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 last line of the loop, but that just messes things up. Any help would be appreciated--thanks.
16
2204
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 temporarily back to the OS so that it doesn't seem like the current program is consuming 50% of cpu resource? The said loop had to process 32 million records in an structure array in memory, and when it goes into this loop. Well the system...
16
6317
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 values of colA and call the Update method. How can I do this in VB.NET and SqlDataAdapter ? Thank you. m_cmdSQL = New SqlClient.SqlCommand With m_cmdSQL .Connection = adoCon
3
2209
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 to all previous posters whose ideas and code I have taken from these forums to get me this far!!) UserId comes in from a combo box also on the same form, the focus is then shifted to the password textbox for password entry and then the user clicks...
3
1511
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) = each($attribs)) { echo $key."has the value".$val."<br>";
0
1289
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 code and now I think There might be a better way of doing it than what I have been doing. Here's the code as far as it goes. Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click '...
2
19316
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 iterates a specified number of times, requires you to also implement or decrement some sort of Loop Counter, while a For...Next Loop does that work for you. Both Loops will provide the same results, but the For...Next Loop is substantially faster. One...
0
10505
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10035
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9090
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7580
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6813
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5471
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4149
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3764
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2945
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.