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

Bill Benson bensonforums at gmail.com
Thu Jul 30 21:05:49 CDT 2015


Simpler last If...?:
...
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  NumberParts(item-1) mod 2 = 0 Then
        Result = SumEven
    Else
        Result = SumOdd
    End If
On Jul 29, 2015 3:42 AM, "Gustav Brock" <gustav at cactus.dk> wrote:

> 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
> --
> AccessD mailing list
> AccessD at databaseadvisors.com
> http://databaseadvisors.com/mailman/listinfo/accessd
> Website: http://www.databaseadvisors.com
>


More information about the AccessD mailing list