By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
448,584 Members | 1,065 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 448,584 IT Pros & Developers. It's quick & easy.

Looping Problem

P: n/a
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("Descrip tion " &
idx).ToString <> "" Then
ReDim Preserve arDescriptions(cnt)
arDescriptions(cnt) =
SpecsDataSet.Tables("Specs").Rows(0).Item("Descrip tion " & 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
--
Joe Goeke
Oct 20 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
CanoeGuy wrote:
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("Descrip tion " &
idx).ToString <> "" Then
ReDim Preserve arDescriptions(cnt)
arDescriptions(cnt) =
SpecsDataSet.Tables("Specs").Rows(0).Item("Descrip tion " &
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

--
------------------------------------------------------------------------
Get LLBLGen Pro, productive O/R mapping for .NET: http://www.llblgen.com
My .NET blog: http://weblogs.asp.net/fbouma
Microsoft MVP (C#)
------------------------------------------------------------------------
Oct 21 '05 #2

P: n/a
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
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("Descrip tion " &
idx).ToString <> "" Then
ReDim Preserve arDescriptions(cnt)
arDescriptions(cnt) =
SpecsDataSet.Tables("Specs").Rows(0).Item("Descrip tion " & 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
--
Joe Goeke

Oct 21 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.