Re: Help With Nested Loop
I suppose number1 > 100 at the beginning, right?
because it will never become 100 within your cycle and your initial condition (until number1 = 100) won't happen. If it's zero in the beginning then this line will have your parent loop cycle only once:
Code:
If number1 <= 0 Then Exit Do
There's no need to use counter2 you can increment counter1 in the nested loop with the same result.
For the nested loop I suggest you use For ... Next construction (or For Each if you need to iterate through all of the rows):
Code:
For intCurrentIndex = whateverthestartingvalueis To ds.Tables(0).Rows.Count - 1
counter1 +=1
txtResults.Text = ds.Tables(0).Rows(intCurrentIndex).Item("Results").ToString()
Next
Mind the fact that txtResults.Text will contain only the last item because you assign a new text with each loop. If you need to see all results you should add text to it, not change it.
Code:
txtResults.AppendText(ds.Tables(0).Rows(intCurrentIndex).Item("Results").ToString() & Environment.NewLine())
Re: Help With Nested Loop
Using Do loops to count is a poor choice. That's what For loops are for. If you want to traverse a DataTable then you should use For and/or For Each loops:
vb.net Code:
For Each row As DataRow In myDataTable.Rows
For Each column As DataColumn In myDataTable.Columns
MessageBox.Show(row(column).ToString())
Next
Next
vb.net Code:
For rowIndex As Integer = 0 To myDataTable.Rows.Count - 1
Dim row As DataRow = myDataTable.Rows(rowIndex)
For columnIndex As Integer In myDataTable.Columns.Count - 1
MessageBox.Show(row(columnIndex).ToString())
Next
Next