VBA Pass Array by link and content change

VBA question. I use it to create Solidworks macros, but that doesn't matter.

Can someone explain the syntax to pass an array (1-dimensional type of Double, length three) to a routine or function so that I can modify the contents. I know that they need to be passed by reference. I say the exact syntax, because everything I try, I get a type mismatch error when calling a subroutine / function.

All I'm looking for is the correct Dim statement for the Doubles array, initializing the statement to make all the array values ​​zero, and then the subroutine call request and the subroutine title that I need. Please be specific if I need to use a variant type or a dynamic array, even if I already know the type and size of the array. Use a function or sub, I don't care what.

My code works fine, but I'm tired of avoiding function calls and routines when I use arrays. I looked at numerous documents and similar questions here, but I just can't understand. Many thanks.

+5
source share
1 answer

This is a pretty trivial example:

Option Explicit Sub foo() Dim myArray(1 To 3) As Double 'The array is initialized with zero-values Call bar(myArray) MsgBox myArray(3) End Sub Sub bar(ByRef dblArray() As Double) dblArray(1) = 123 dblArray(2) = 345 dblArray(3) = 33456 End Sub 
+10
source

Source: https://habr.com/ru/post/1212631/


All Articles