SAFEARRAY
VBA Internals: Array Variables and Pointers in Depth
This is the next installment of a series of deep-dives into the structure and implementation of variables in Visual Basic for Applications. For the previous posts, see the following:
- What’s in a variable - Categories of variables in VBA, by implementation
- Getting Pointers - Overview of how to obtain pointers in VBA
- Scalar Variables and Pointers in Depth - Details of numeric scalar variables and pointers
- String Variables and Pointers in Depth - Details of string variables and pointers
In this post, I will cover the details of array variables and pointers. See Scalar Variables and Pointers in Depth for additional background and for the code for the utility functions HexPtr
and Mem_ReadHex
.
Pointers and memory for array variables
Like strings, arrays in VBA are treated semantically like value types but are implemented as reference types. Also like strings, arrays in VBA are implemented using a COM automation structure. For arrays the supporting COM type is the safe array, which comes with a large group of utility functions.