Solved

Manipulate Arrays without knowing dimensionality

Posted on 1998-06-03
4
128 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

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone 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

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
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 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…

829 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