473,466 Members | 1,447 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

How to loop through a dynamic jagged array?

37 New Member
There's plenty of information out there showing how to loop through a jagged array when you know the dimensions, but I can't find anything that tells how to loop through dynamic jagged arrays.

Here's pseudo-code for what I want to do:

Expand|Select|Wrap|Line Numbers
  1. For (each element in array, dimension two)
  2.      For (each element in array, dimension one)
  3.          (add element two to table column)
  4.          (add element one to table, next column)...
  5.      Next
  6. Next
  7.  
So my question is how to construct the "For" statement so that I'm referencing the correct dimension? Do I need empty curly braces or empty parentheses in place of the other dimension?

Thanks in advance.
Oct 6 '16 #1

✓ answered by ADezii

  1. I am a little confused as to your request, but you can reference the proper Dimension when using LBound() and UBound() to Loop thru the Array Elements, as in:
    Expand|Select|Wrap|Line Numbers
    1. Dim intD1 As Integer
    2. Dim intD2 As Integer
    3. Dim aTest(1 To 2, 1 To 4) As Integer
    4.  
    5. aTest(1, 1) = 10
    6. aTest(1, 2) = 20
    7. aTest(1, 3) = 30
    8. aTest(1, 4) = 40
    9. aTest(2, 1) = 100
    10. aTest(2, 2) = 200
    11. aTest(2, 3) = 300
    12. aTest(2, 4) = 400
    13.  
    14.  
    15. For intD1 = LBound(aTest, 1) To UBound(aTest, 1)
    16.   For intD2 = LBound(aTest, 2) To UBound(aTest, 2)
    17.      Debug.Print CStr(intD1) & "/" & CStr(intD2) & ": " & aTest(intD1, intD2)
    18.   Next
    19. Next
  2. OUTPUT:
    Expand|Select|Wrap|Line Numbers
    1. 1/1: 10
    2. 1/2: 20
    3. 1/3: 30
    4. 1/4: 40
    5. 2/1: 100
    6. 2/2: 200
    7. 2/3: 300
    8. 2/4: 400
  3. If my assumption is incorrect, kindly clarify.

6 2530
ADezii
8,834 Recognized Expert Expert
  1. I am a little confused as to your request, but you can reference the proper Dimension when using LBound() and UBound() to Loop thru the Array Elements, as in:
    Expand|Select|Wrap|Line Numbers
    1. Dim intD1 As Integer
    2. Dim intD2 As Integer
    3. Dim aTest(1 To 2, 1 To 4) As Integer
    4.  
    5. aTest(1, 1) = 10
    6. aTest(1, 2) = 20
    7. aTest(1, 3) = 30
    8. aTest(1, 4) = 40
    9. aTest(2, 1) = 100
    10. aTest(2, 2) = 200
    11. aTest(2, 3) = 300
    12. aTest(2, 4) = 400
    13.  
    14.  
    15. For intD1 = LBound(aTest, 1) To UBound(aTest, 1)
    16.   For intD2 = LBound(aTest, 2) To UBound(aTest, 2)
    17.      Debug.Print CStr(intD1) & "/" & CStr(intD2) & ": " & aTest(intD1, intD2)
    18.   Next
    19. Next
  2. OUTPUT:
    Expand|Select|Wrap|Line Numbers
    1. 1/1: 10
    2. 1/2: 20
    3. 1/3: 30
    4. 1/4: 40
    5. 2/1: 100
    6. 2/2: 200
    7. 2/3: 300
    8. 2/4: 400
  3. If my assumption is incorrect, kindly clarify.
Oct 7 '16 #2
clotposlo3
37 New Member
ADezii,

Thank you for your reply. I would like to rearrange the data from a GetRows statement into a new table. While I know there is data in at least two fields, the others may or may not have data, in which case, I don't want to add them to the new table. This makes it impossible to DIM the array to any fixed size and makes referencing the dimensions rather tricky.

This may be another case of making things hard on myself, as I've been told here before. At this point, the best option may be to give up on the jagged array and try something else, such as working with a single record at a time from GetRows instead of the whole recordset at once.

I'm sure I'll have more stupid/strange questions along the way, so thank you very much for sharing your expertise.
Oct 7 '16 #3
ADezii
8,834 Recognized Expert Expert
You are quite welcome, glad to assist. Why not set Criteria on the Data Source of the Recordset to reflect only those Records that would be added to a New Table. With this approach, GetRows() would only retrieve relevant Records. Is a Make Table Query a viable option?
Oct 7 '16 #4
clotposlo3
37 New Member
ADezii,

I need all the data from the recordset (except nulls), but it will be rearranged in the new table. Some fields will be combined into a single field. Another field will contain info about the group each of the elements in the first field belong to. There will be duplicates in both fields. Once this is accomplished, I need to perform calculations on both fields to find the number of duplicates, and then perform calculations on those calculations.

I'm afraid I don't know any easy way to do what I want to do. Your suggestions are always welcome!
Oct 7 '16 #5
ADezii
8,834 Recognized Expert Expert
Can you possibly Upload a subset of the Data, and the results that you would like to see from the processing of this Data? In this manner it would be crystal clear what you are trying to accomplish and a solution may be more easily arrived at.
Oct 7 '16 #6
clotposlo3
37 New Member
I'm happy to say I resolved my problem, although I did have to give up on the jagged array. It took a surprisingly small nested loop to process the entire recordset from a single GetRows statement and add it all to the new table in exactly the way I wanted.

The most helpful piece of advice was from those who told me (in other posts) that I've been making things harder on myself than they have to be. I didn't think I could do all the required processing on all the different kinds of data and get it into the new table with one fairly simple loop. That was a valuable lesson!
Oct 8 '16 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: ron | last post by:
Hi, I am Serializing a Jagged Array and it works fine. The qusetion i have is way dose the XML formatting do the following. I have a single-dimensional array that has 21 elements of type int,...
2
by: Jannis Linxweiler | last post by:
Hi NG! I have a problem with my unsafe code. I'd like to get a pointer on a jagged array like this: double arr = new double; for (int i....); arr = new double;
6
by: Carlos | last post by:
Ok I have the following Jagged array double mData = new double; for (int x = 0; x <= 259200-1; x++) { mData=new double; } And I load the data in to the array :
2
by: deko | last post by:
I trying to create a jagged array of two arrays, with the second array being an array of two-dimensional arrays. A graphical representation might look like this: x y y y x y x y y x ...
0
by: craig.conboy | last post by:
Using MC++ .Net 2.0, with the CLR Profiler (from Microsoft) I am seeing that 3 blocks of memory, each ~48MB in size, being allocated by some code that initializes a managed array. It is a jagged...
2
by: tiberiu.motoc | last post by:
Hi. I've asked this question on the MSDN forums, but I've had no replies. I'm really stuck, so I'm gonna try my luck here. I have a Java web service which contains a simple function; the...
5
by: TS | last post by:
is there some code somewhere that does this? i have a jagged array that is not jagged, it has an equal number of rows and columns in each array so it should convert but want to get the code to do...
17
by: =?Utf-8?B?U2hhcm9u?= | last post by:
Hi Gurus, I need to transfer a jagged array of byte by reference to unmanaged function, The unmanaged code should changed the values of the array, and when the unmanaged function returns I need...
3
by: pinkfloydfan | last post by:
Hi there I have a C# program that produces a lot of data that I currently store in a jagged array and I have a couple of questions that I was hoping someone might shed some light on for me...
7
by: ASIM ABBAS | last post by:
Sir plz explain and also send me the code of dynamic jagged array i make static jagged array but how we make dynamic jagged array
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
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...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...

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.