FastPlymouth Posted February 7, 2006 Posted February 7, 2006 Hey All, I've racked my brain for 2 days trying to figure this one out... I have a button event handler that loops through a repeater comparing textbox values within each row to the corresponding row in a datatable. As far as I can tell all of the code inside my loop is fine, but for some reason the loop would only execute for every other iteration. Puzzled, I stripped the loop down until it was nothing but the following: Dim i As Integer = 0 Dim debug As String For i = 0 To 6 Step 1 debug = debug & "," & i i = i + 1 Next lblError.Text = debug Notice that I even added the "step 1" just to be sure. My output is ",0,2,4,6". Am I missing something here!??!? I've been coding vb.net for well over a year now - is it possible that I somehow hamfisted a basic construct? Thinking that the problem had something to do with the event handler itself (longshot) I moved the above code into my PageLoad... same thing!! Does anyone have ANY idea what could cause such a ridiculous condition? I have a feeling it's something stupid and easy that I forgot - if this is the case I'll never be able to show my face here again :) Thanks! K Quote
Nate Bross Posted February 7, 2006 Posted February 7, 2006 (edited) This line is what is causing the issue. i = i + 1 Try something like this. The For...Next Loop automatically increments your variable for you, defaulting to positive one. For i as Integer = 0 to 6 Console.WriteLine(i.ToString()) Next i The above code just has the wrong type of Loop around it. Dim i as Integer = 0 Do While i < 7 Console.WriteLine(i.ToString()) i += 1 Loop Edited February 7, 2006 by Nate Bross Quote ~Nate� ___________________________________________ Please use the [vb]/[cs] tags on posted code. Please post solutions you find somewhere else. Follow me on Twitter here.
FastPlymouth Posted February 7, 2006 Author Posted February 7, 2006 Nate - You are the man! Thank you. Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.