Array Question


I have an array with the values (0, 4, 5, 6, 10, 11) which is returned to me by a loop that queries certain properties of objects.

I’m looking for a way to output all related values as a group. So the result for the example would be

  • 0
  • 4, 5, 6
  • 10, 11

Looks like the result needs to be an Array with an array or Pairs (0:0, 4:6, 10:11). How can I get this return?


You don’t provide much in the way of details (all the properties are the same type, or not? do you know how many columns in each case, or not?), so here is a shot in the dark:

  • I would suggest a multi-dimensional array. One row is one “group”. The question is how many columns do you need, and do you know how many columns are possible?
  • If the type of data differs, then an array of classes where each “column” is a property of the class, would be another possible solution.
  • Perhaps a dictionary?

If we understand the what and the why a bit better, I am certain that other more elegant or more efficient solutions can be suggested.

  • Create a Class called GroupClass

  • Create two properties in GroupClass:

    • High (Integer)
    • Low (Integer)
  • Create an array of GroupClass: DIM Groups() AS GroupClass

    • For each element of the array, define the high and low limits of that group


[code]DIM Groups() AS GroupClass ’ List of Groups

// Populate Groups array here

DIM Data() AS INTEGER ’ Array of data

// Populate Data array here

REDIM Result (Groups.Ubound)

FOR iGroup AS INTEGER = 0 TO Groups.Ubound
FOR iData AS INTEGER = 0 TO Data.Ubound
IF Data(iData) >= Groups(iGroup).Low AND Data(iData) <= Groups(iGroup).High THEN
Result(iGroup) = Result(iGroup) + Str (Data(iData)) + ", "
NEXT iData
NEXT iGroup

EDIT: Fixed REDIM Result (Groups.Ubound)