473,320 Members | 1,977 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,320 software developers and data experts.

Interesting problem: My For loop doesn't want to loop!

I am writing a program in VB.NET and as I was debugging a problem I noticed my For loop doesn't want to loop!
I originally had a upper bound which was an expression and it wasn't working. WHen I noticed this I changed the upper bound for a simple digit. As I step through my code, I see that it simply goes through the loop once and continues on it's merry way. Now I have programmed in Java, C++, and even Modula 3 before and I have never seen this EVER!
Do I have something wrong with my settings or what? I'm really stumped!
H E L P!!

here's the code:

dim i as Integer
For i = 0 To i = 5
'objdsBook is a dataset
output = output & objdsBook.BookCondition(i).Item(0).ToString
Next i
Nov 20 '05 #1
3 1347
Wouldn't it be

Dim i as Integer

For i = 0 To 5
'objdsBook is a dataset
output = output & objdsBook.BookCondition(i).Item(0).ToString
Next i

Not, i = 0 To i = 5

"Rudy" <an*******@discussions.microsoft.com> wrote in message
news:DE**********************************@microsof t.com...
I am writing a program in VB.NET and as I was debugging a problem I noticed my For loop doesn't want to loop! I originally had a upper bound which was an expression and it wasn't working. WHen I noticed this I changed the upper bound for a simple digit.
As I step through my code, I see that it simply goes through the loop once
and continues on it's merry way. Now I have programmed in Java, C++, and
even Modula 3 before and I have never seen this EVER! Do I have something wrong with my settings or what? I'm really stumped!
H E L P!!

here's the code:

dim i as Integer
For i = 0 To i = 5
'objdsBook is a dataset
output = output & objdsBook.BookCondition(i).Item(0).ToString
Next i

Nov 20 '05 #2

Ok, thanks Mark, that was it.
Man I am soooo embarrased. What a simple mistake.

Thanks a million!
Nov 20 '05 #3
Rudy,
You may want to consider using Option Strict On, you would have received a
compile error to the effect "Option Strict On disallows implicit conversions
from 'boolean' to 'integer' on the expression "i = 5" on the For statement.
I find compile errors easier to fix, then obscure runtime behavior.
Unfortunately Option Strict On requires you to be more specific in your code
(requiring use of CType & DirectCast more) as it disallows late binding &
some implicit conversions. However this generally means you code may execute
faster...

I would also recommend you consider using a StringBuilder instead of string
concatenation.
dim i as Integer Dim sb As New System.Text.StringBuilder For i = 0 To 5
'objdsBook is a dataset
sb.Append(objdsBook.BookCondition(i).Item(0))
Next i output = sb.ToString()

For 6 rows using StringBuilder may not make much of a difference, however
for 600 rows I'm sure it will.

Hope this helps
Jay

"Rudy" <an*******@discussions.microsoft.com> wrote in message
news:DE**********************************@microsof t.com... I am writing a program in VB.NET and as I was debugging a problem I noticed my For loop doesn't want to loop! I originally had a upper bound which was an expression and it wasn't working. WHen I noticed this I changed the upper bound for a simple digit.
As I step through my code, I see that it simply goes through the loop once
and continues on it's merry way. Now I have programmed in Java, C++, and
even Modula 3 before and I have never seen this EVER! Do I have something wrong with my settings or what? I'm really stumped!
H E L P!!

here's the code:

dim i as Integer
For i = 0 To i = 5
'objdsBook is a dataset
output = output & objdsBook.BookCondition(i).Item(0).ToString
Next i

Nov 20 '05 #4

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

Similar topics

47
by: fb | last post by:
Hi Everyone. Thanks for the help with the qudratic equation problem...I didn't think about actually doing the math...whoops. Anyway... I'm having some trouble getting the following program to...
20
by: Doug Thews | last post by:
I ran into an interesting re-pain delay after calling the Abort() method on a thread, but it only happens the very first time I call it. Every time afterward, there is no delay. I've got a...
15
by: Andrew Maclean | last post by:
I guess this problem can be distilled down to: How do I search through a string, find the first matching substring, replace it, and continue through the string doing this. Can replace_if() be used...
2
by: Michael Sutherland | last post by:
Here's an interesting problem I've come across. I'm writing a program that essentially generates random strings (its a simulator of the game Boggle) and sends them to a function that does a...
9
by: Jerim79 | last post by:
Here it is: <?php if($_SERVER=='POST'){ $Number=$_POST; $Email=$_POST; $Number2=0; $error=0;
40
by: nufuhsus | last post by:
Hello all, First let me appologise if this has been answered but I could not find an acurate answer to this interesting problem. If the following is true: C:\Python25\rg.py>python Python...
12
by: Daniel Earwicker | last post by:
I wrote two trivial test programs that do a billion iterations of a virtual method call, first in C# (Visual Studio 2005): Thing t = new DerivedThing(); for (System.Int64 n = 0; n < 10000000000;...
16
by: Hendrik van Rooyen | last post by:
I thought I would share this nasty little gotcha with the group. Consider the following code fragment: <start> print 'starting kbd thread' keyboard_thread = thread.start_new_thread(kbd_driver...
16
by: Ed Bitzer | last post by:
Trying to send groups of email with program using System.Net.Mail. I do not clear MailMessage but repeatedly loop changing only the Bcc entries. Works fine if all addresses are valid. As a simple...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.