Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

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

Posted (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 by Nate Bross

~Nate�

___________________________________________

Please use the [vb]/[cs] tags on posted code.

Please post solutions you find somewhere else.

Follow me on Twitter here.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...