Looping Problem

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have an array that I am populating from a database. I am looping through
the array to write the values to a datagrid. At this point, I'm stuck. I
can't figure out how to read the first four values from the array, then go on
to the next four values, then go on to the to the next, etc.

This is an example of the code I have so far.

cnt = 0
start = 1
For idx = 1 To 10
If SpecsDataSet.Tables("Specs").Rows(0).Item("Description " &
idx).ToString <> "" Then
ReDim Preserve arDescriptions(cnt)
arDescriptions(cnt) =
SpecsDataSet.Tables("Specs").Rows(0).Item("Description " & idx).ToString
row = dtScrewDims.NewRow()
dtScrewDims.Rows.Add(row)
row.Item(cnt) = arDescriptions(cnt)
End If
'We have to figure out a way to print out the first four dim. fields, then
go to
'the next four, then to the next, etc. within this loop. cnt is the variable
'that we need to use to increment by.
For idxDims = start to (column_count + start - 2)
row.Item(idxDims) = arDimensions(cnt) 'These items come from the
arDimensions array.
cnt = cnt + 1
Next
cnt = 0 'I know that doing this resets the count to zero and causes my
problem, but I can't figure out how to move to the next number without
getting a "column(cnt) cannot be found error.
Next 'idx
 
CanoeGuy said:
I have an array that I am populating from a database. I am looping
through the array to write the values to a datagrid. At this point,
I'm stuck. I can't figure out how to read the first four values from
the array, then go on to the next four values, then go on to the to
the next, etc.

This is an example of the code I have so far.

cnt = 0
start = 1
For idx = 1 To 10
If SpecsDataSet.Tables("Specs").Rows(0).Item("Description " &
idx).ToString <> "" Then
ReDim Preserve arDescriptions(cnt)
arDescriptions(cnt) =
SpecsDataSet.Tables("Specs").Rows(0).Item("Description " &
idx).ToString row = dtScrewDims.NewRow()
dtScrewDims.Rows.Add(row)
row.Item(cnt) = arDescriptions(cnt)
End If
'We have to figure out a way to print out the first four dim. fields,
then go to
'the next four, then to the next, etc. within this loop. cnt is the
variable 'that we need to use to increment by.
For idxDims = start to (column_count + start - 2)
row.Item(idxDims) = arDimensions(cnt) 'These items come from the
arDimensions array.
cnt = cnt + 1
Next
cnt = 0 'I know that doing this resets the count to zero and
causes my problem, but I can't figure out how to move to the next
number without getting a "column(cnt) cannot be found error.
Next 'idx

dim x As Integer
dim y As Integer
for y = 0 to NumberOfRows
for x = 0 to NumberOfColumns
' the value for row Y, column x is:
' arDimensions(y*NumberOfColumns + x)
next
next


FB

--
 
Joe,
I have an array that I am populating from a database. I am looping through
the array to write the values to a datagrid.

This statement is confusing for me, because there is normally not any need
to build an array for a datagrid from a dataset.Table. That class is the
most optimized in relation to a datagrid (windowsform).

The second point is that a fixed array is very time consuming when you
redimensional that constantly, because than there is constantly a new array
created. For that is the arraylist one of the better approaches.

Therefore can you tell more what you want to achieve (and than the answer is
probably quiet simple).

Cor
 
Back
Top