Solved

Manipulate Arrays without knowing dimensionality

Posted on 1998-06-03
4
127 Views
Last Modified: 2010-05-03
I have a function which takes an array. I don't know what the dimensionality of the array is (it could have one, two, three dimensions, who knows how many?)

I would like to be able to determine the number of dimensions in the array, and a generic way of going through the array, perhaps by slicing the array into small arrays of n-1 dimensions.

Perhaps 100 points is too low, but let's see what kind of answers I get... Thanks.
0
Comment
Question by:rikonigsberg
  • 2
  • 2
4 Comments
 
LVL 9

Accepted Solution

by:
Dalin earned 100 total points
ID: 1462450
rikonigsberg,
This code should allow you to determine the demension of an array and it Up/low limits of each demension
1. add a module, declare::
Type ldemen
   FirstEle As Long
   LastEle As Long
   End Type

In the form's declaration area, add:
Dim A(1 To 50, 1 To 35, 1 To 5) As Integer
 Dim MyArray() As ldemen

drop a command to the form, in the click event, add:
Dim i As Integer
Dim lMore As Boolean
Dim lLimit As Long

On Error GoTo ErrorTrap

lMore = True
i = 1
Do While lMore = True
     lLimit = UBound(A, i)
     
     ReDim Preserve MyArray(i)
     MyArray(i).LastEle = lLimit
     MyArray(i).FirstEle = LBound(A, i)
     i = i + 1
    Loop
   
ErrorTrap:
   If Err.Number = 9 Then
   
        lMore = False
        MsgBox "The Array has" & CStr(i - 1) & "Elements"
    Else
      '  Other Error, do what ever you need to
    End If


If you tell me a little more of how you want to go through it, I can be more constructive in suggest.
Regards
Dalin
0
 

Author Comment

by:rikonigsberg
ID: 1462451
rikonigsberg,
As I mentioned earlier, if you can tell me what you want to do twith it, I can better suggest.
If you have questions, let me know
Regards
Dalin


To go throught elements by element, you can put the demention (i-1) in the routine shown) somewhere, for example, in a Global variable, say gInMyDim,
You declare in a Module's general declaration:
Global gInMyDim as Integer

Then in the routine about, instead of say MsgBox, add:
gInMyDim = i-1

Now when you want to go through each elements, you do:

Dim j as Integer
Din k as Integer ' asssume you have less then 32000 elements in any demesion, otherwise it need to be long.

For j = 1 to gInMyDim
    For k= lBound(A,j) to UBound(a, j)
       ' assume the array named A
       A(j, k) = 3
       'Do something
       Next k
Next j






0
 
LVL 9

Expert Comment

by:Dalin
ID: 1462452
What I need to do is receive an array of unknown dimensions and access all the elements in it (assume any datatype)
0
 

Author Comment

by:rikonigsberg
ID: 1462453
What I need to do is receive an array of unknown dimensions and access all the elements in it (assume any datatype).

In fact, I've figured it out by now, so thanks, though, and thanks for the info provided.
0

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question