473,405 Members | 2,334 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

Looping Problem

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
2 1778
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

11
by: Lyle Fairfield | last post by:
The stored procedure script below is an example of how looping, case statements and output parameters can be used in MS-SQL stored procedures to accomplish things for which we may have had to use...
7
by: Ken | last post by:
Hi All - I have a filtered GridView. This GridView has a check box in the first column. This check box is used to identify specific rows for delete operations. On the button click event I...
13
by: JayCallas | last post by:
I know this question has been asked. And the usual answer is don't use cursors or any other looping method. Instead, try to find a solution that uses set-based queries. But this brings up...
5
by: Jeff | last post by:
Hey gang. I have a script that gets stats from a mssql db, and then inserts those stats into a temp table. where i can work with them as i wish. the problem is it isn't looping through all the...
6
by: Luke - eat.lemons | last post by:
Hi, Im pretty new to asp so all light on this question would be great. Basically i need to test to see what value is set (where to retrieve the data from) so ive done it like this: If...
1
by: assgar | last post by:
Hello I have changed the process code abit so it receives the data from the form and ensures the data in array format. This has eliminated my previous error. The problem I am experiencing...
3
by: Andy | last post by:
Hello, I have the following situation: Thread A is allocating a dataset, doing some low-level calculations and storing a pointer to the dataset in a std::list via push_back. Thread B should...
3
by: assgar | last post by:
Hi I am having problem with my loping. I don't know if I have chosen the correct approach. GOAL: I need to insert into a table event types for a specific date range. The calendar the event...
3
by: chiku1523 | last post by:
Hi, Please find the following code. In function setAnswers, I am looping with each question. I have inner loop, which is looping for each answers of the questions. If any of the answer for question...
1
by: Robocop | last post by:
Having just started using C again after some years off, i've been stumped by a problem i think someone more experienced could probably solve pretty easily. I have these 4 objects (vectors), and i...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.