Drew Wutka
DWUTKA at Marlow.com
Wed Mar 12 11:57:23 CDT 2008
So, if we want one function with a paramarray argument to hand data to
another function with a paramarray argument:
Dim tmpSum As Long
Dim strTemp As String
Function MultipleRunningSums(ParamArray tmpValues() As Variant)
Dim tmpValueToRunSumFor
For Each tmpValueToRunSumFor In tmpValues
RunningSum tmpValueToRunSumFor
Next
End Function
Function RunningSum(ParamArray tmpValues() As Variant)
Dim tmpCurrentValue As Long
strTemp = ""
tmpSum = 0
DoTheWorkForRunningSum tmpValues
strTemp = Left(strTemp, Len(strTemp) - 3)
If Val(strTemp) <> tmpSum Then Debug.Print strTemp & " = " & tmpSum
tmpCurrentValue = tmpSum
If tmpSum < 100 Then RunningSum tmpCurrentValue, tmpValues
End Function
Function DoTheWorkForRunningSum(ByVal tmpPossibleArray As Variant)
Dim tmpElement
For Each tmpElement In tmpPossibleArray
If IsArray(tmpElement) Then
DoTheWorkForRunningSum tmpElement
Else
tmpSum = tmpSum + Val(tmpElement)
strTemp = strTemp & tmpElement & " + "
End If
Next
End Function
Testing Results:
?MultipleRunningSums(1,2,3,4)
1 + 1 = 2
2 + 1 + 1 = 4
4 + 2 + 1 + 1 = 8
8 + 4 + 2 + 1 + 1 = 16
16 + 8 + 4 + 2 + 1 + 1 = 32
32 + 16 + 8 + 4 + 2 + 1 + 1 = 64
64 + 32 + 16 + 8 + 4 + 2 + 1 + 1 = 128
2 + 2 = 4
4 + 2 + 2 = 8
8 + 4 + 2 + 2 = 16
16 + 8 + 4 + 2 + 2 = 32
32 + 16 + 8 + 4 + 2 + 2 = 64
64 + 32 + 16 + 8 + 4 + 2 + 2 = 128
3 + 3 = 6
6 + 3 + 3 = 12
12 + 6 + 3 + 3 = 24
24 + 12 + 6 + 3 + 3 = 48
48 + 24 + 12 + 6 + 3 + 3 = 96
96 + 48 + 24 + 12 + 6 + 3 + 3 = 192
4 + 4 = 8
8 + 4 + 4 = 16
16 + 8 + 4 + 4 = 32
32 + 16 + 8 + 4 + 4 = 64
64 + 32 + 16 + 8 + 4 + 4 = 128
Hope this helps.
Drew
The information contained in this transmission is intended only for the person or entity to which it is addressed and may contain II-VI Proprietary and/or II-VI Business Sensitive material. If you are not the intended recipient, please contact the sender immediately and destroy the material in its entirety, whether electronic or hard copy. You are notified that any review, retransmission, copying, disclosure, dissemination, or other use of, or taking of any action in reliance upon this information by persons or entities other than the intended recipient is prohibited.