Solved

Manipulate Arrays without knowing dimensionality

Posted on 1998-06-03
4
130 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

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…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
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…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

707 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