Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Manipulate Arrays without knowing dimensionality

Posted on 1998-06-03
4
Medium Priority
?
133 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 200 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: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying 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

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…
Suggested Courses

604 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