[AccessD] How do I calculate the sum numbers of an array

Gustav Brock gustav at cactus.dk
Wed Jul 29 02:40:51 CDT 2015


Hi Kostas

Just loop the numbers and sum the numbers in odds and evens:

<code>
Public Function SumString(ByVal Numbers As String) As Long

    Dim NumberParts As Variant
    Dim SumEven     As Long
    Dim SumOdd      As Long
    Dim Result      As Long
    Dim Item        As Long
            
    NumberParts = Split(Numbers, " ")
    
    For Item = LBound(NumberParts) To UBound(NumberParts)
        If Item Mod 2 = 0 Then
            SumEven = SumEven + Val(NumberParts(Item))
        Else
            SumOdd = SumOdd + Val(NumberParts(Item))
        End If
    Next
    If (SumOdd + SumEven) Mod 2 = 0 Then
        Result = SumEven
    Else
        Result = SumOdd
    End If
    
    SumString = Result
    
End Function
</code>

________________________________________
Fra: AccessD <accessd-bounces at databaseadvisors.com> på vegne af Kostas Konstantinidis <kost36 at otenet.gr>
Sendt: 29. juli 2015 08:59
Til: Access Developers discussion and problem solving
Emne: [AccessD] How do I calculate the sum numbers of an array

Hi again,
I am trying to make a formula calculation to be able to figure out easily
and faster a unique key indicator very important for my personal usage.
So, I use a field with a generated string like
50 150 22 35 50 68 etc
The total group numbers are 6
The formula calculation I need depends of the result of the total group
numbers
if the total group is an even number it must sum the even parts of group
(150+35+68 = 253)
else if it's an odd number it must sum the odd parts of group (50+22+50=122)

I ask for your help another once

thank's
/kostas


More information about the AccessD mailing list