Solved

Manipulate Arrays without knowing dimensionality

Posted on 1998-06-03
4
125 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

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…
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

762 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now