06-22-2023, 03:53 PM
(This post was last modified: 06-22-2023, 04:04 PM by Kernelpanic.)
@bplus - "ReDim" is useless here, since it has not yet been initialized. - The output is interesting. I know how that happens, but was that intentional? I don't really understand what you're trying to show. 
tot$ is also redundant
The edition
1st row: 6 + 3 = 9 + 5 = 14 + 7 = 21 . . . always 2 more.
2nd row: 6 + 9 = 15 + 14 = 29 + 21 = 50 . . .
In the 2nd row, the results of the addition from the 1st row are added. The end result is correct in both cases, but I find the whole thing quite confusing.

Code: (Select All)
$Console:Only
Dim Shared mySharedArray(1 To 20) As Long
For i = 1 To 20
mySharedArray(i) = i * i
Next
Dim out10(1 To 10) As Integer
first10Plus5 = first10squaresPlus&(5, out10())
For i = 1 To 10
Print out10(i)
Next
Print "Total was: "; first10Plus5
End
Function first10squaresPlus& (X, outputFirst10() As Integer)
Print X
Print
For i = 1 To 10
outputFirst10(i) = mySharedArray(i) + X
Print outputFirst10(i)
tot& = tot& + outputFirst10(i)
Print Tab(5); tot&
Next
Print
first10squaresPlus& = tot&
End Function
tot$ is also redundant

Code: (Select All)
Function first10squaresPlus& (X, outputFirst10() As Integer)
Print X
Print
For i = 1 To 10
outputFirst10(i) = mySharedArray(i) + X
outputFirst10 = outputFirst10 + outputFirst10(i)
Next
Print
first10squaresPlus& = outputFirst10 'tot&
End Function
The edition
1st row: 6 + 3 = 9 + 5 = 14 + 7 = 21 . . . always 2 more.
2nd row: 6 + 9 = 15 + 14 = 29 + 21 = 50 . . .
In the 2nd row, the results of the addition from the 1st row are added. The end result is correct in both cases, but I find the whole thing quite confusing.
![[Image: Shared-Array2023-06-22.jpg]](https://i.ibb.co/TqYShHp/Shared-Array2023-06-22.jpg)