473,569 Members | 2,790 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.BookC ondition(i).Ite m(0).ToString
Next i
Nov 20 '05 #1
3 1357
Wouldn't it be

Dim i as Integer

For i = 0 To 5
'objdsBook is a dataset
output = output & objdsBook.BookC ondition(i).Ite m(0).ToString
Next i

Not, i = 0 To i = 5

"Rudy" <an*******@disc ussions.microso ft.com> wrote in message
news:DE******** *************** ***********@mic rosoft.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.BookC ondition(i).Ite m(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.Str ingBuilder For i = 0 To 5
'objdsBook is a dataset
sb.Append(objds Book.BookCondit ion(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*******@disc ussions.microso ft.com> wrote in message
news:DE******** *************** ***********@mic rosoft.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.BookC ondition(i).Ite m(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
5243
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 work. I want to output a bit pattern from base 10 input. All I get is a zero after the input...I've looked over the code but can't see the...
20
2998
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 delegate inside the UI that I call to update the progress meter. I use the Suspend() and Abort() methods based on button events. I can watch the...
15
3812
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 to do this? Here is a concrete example: If I have a string with sequences of CRLF and possibly just CR's, is there a simple way of replacing the...
2
1236
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 binary search on a word list to see if that string is listed. However, at seemingly random intervals (I've seen it happen on everything from a few dozen...
9
2380
by: Jerim79 | last post by:
Here it is: <?php if($_SERVER=='POST'){ $Number=$_POST; $Email=$_POST; $Number2=0; $error=0;
40
2699
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 2.5.1 (r251:54863, Apr 18 2007, 08:51:08) on win32 Type "help", "copyright", "credits" or "license" for more
12
4475
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; n++) t.method(); Then in C++ (using Visual C++ 2005): Thing *t = new DerivedThing();
16
2747
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 (port_q,kbd_q)) print 'starting main loop' error = Mainloop(s,port_q,active_q_list) <end>
16
1644
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 test I have attempted to send a valid address, then an invalid address which my ISP (Comcast) will reject immediately as "Not our customer". I...
0
7694
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7609
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
8118
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
6278
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...
0
5217
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...
0
3651
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...
0
3636
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2107
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
0
936
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...

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.