tiredofit
Well-known Member
- Joined
- Apr 11, 2013
- Messages
- 1,832
- Office Version
- 365
- 2019
- Platform
- Windows
I prefer to declare arrays by adding the brackets, ie:
instead of:
because I find adding the brackets makes it clearer.
However, in the following code which attempts to return multiple values from a function. I find that adding the brackets causes the program to crash:
The error message is:
Stepping into it, when the code hits this line:
instead of proceeding to End Sub, it calls it again, ie jumps to here:
If instead I wrote:
it's fine.
Why is that?
Thanks
Code:
Dim MyArray() As Variant
instead of:
Code:
Dim MyArray As Variant
because I find adding the brackets makes it clearer.
However, in the following code which attempts to return multiple values from a function. I find that adding the brackets causes the program to crash:
Code:
Option Explicit
Sub GetValues()
Dim Counter As Integer
For Counter = 1 To 3
MsgBox "Value " & Counter & " = " & SomeArray(Counter, 1)
Next Counter
End Sub
Public Function SomeArray() As Variant
Dim DataArray(1 To 3, 1 To 1) As Variant
DataArray(1, 1) = 10
DataArray(2, 1) = 20
DataArray(3, 1) = 30
SomeArray() = DataArray()
End Function
The error message is:
Code:
Run-time error '28'
Out of stack space
Stepping into it, when the code hits this line:
Code:
SomeArray() = DataArray()
instead of proceeding to End Sub, it calls it again, ie jumps to here:
Code:
Public Function SomeArray() As Variant
If instead I wrote:
Code:
SomeArray = DataArray()
it's fine.
Why is that?
Thanks