0

Is there an alternative method to access an array in VBA?

I was creating a N-Dimensional Array Library when I realized that it is impossible to implement such a library of helpers without an alternative method to access an array in VBA...

For example using an array as an index?:

' instead of foo(6,2)=source(1,3,6,2) :
Dim idx1, idx2
idx1 = Array(6,2): idx2 = Array(1,3,6,2)
foo(idx1) = source(idx2)

The idea is to create/copy/change/merge SubArrays. For example:

Dim blnPending as Boolean
Dim idx1, idx2

idx1 = Array(0,0): idx2 = Array(1,3,0,0)
blnPending = True
Do While blnPending
    foo(idx1) = source(idx2)
    blnPending = IndexIncrease (idx1, PivotDimension:= -1)
    IndexIncrease idx2, PivotDimension:= 1 ' second param just to reflect the idea of usage
Loop

Same problem with Redim in this particular

Any idea?

3
  • Perhaps something that can only be made using an Add-In made by VB.NET? (ExcelDNA): stackoverflow.com/questions/6977933/… Commented May 14, 2017 at 2:00
  • I can't see exactly what you're trying to do in your example, but to answer the title question, you can access the SafeArray structure in VBA, using the VarPtrArray API and the RtlMoveMemory API. It's a real hair-puller, though, as Excel crashes on pretty much any bug in your code, so developing takes forever and a day. Commented May 14, 2017 at 4:40
  • Re my previous comment, I used this site quite a bit when learning about pointers in VBA: bytecomb.com/vba-internals-getting-pointers and it does cover arrays. Commented May 14, 2017 at 4:42

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.