Domino Code Fragment

Code Name*
Average the elements in a one-dimensional array of integers
Date*
04/28/2024
Source (or email address if you prefer)*
Rlatulippe@romac.com
IP address:.3.145.170.65
Description*
This Subroutine will take and array of integers and give you the average, sum and difference from average of the integers.
Type*
LotusScript
Categories*
(Misc)
Implementation:
Required Client:
Server:
Limitations:
Comments:
An additional array could be used to hold the differences from average of all the elements. The difference array could be used in place of the messagebox in the second FOR loop. It would be easy to initialize since the bounds
Files/Graphics attachments (if applicable): Code:
Sub aver (numarray As Variant)
Dim lowelts As Integer
'Start of array
Dim numelts As Integer
'Number of elements in the array
Dim uppelts As Integer
'End of Array
Dim i As Integer
Dim total As Integer
'Sum of numbers in the Array
Dim avg As Single
'Average of numbers in the Array
Dim diff As Single
'Difference between each number and the average
Total = 0
lowelts = Lbound(numarray)
numelts = (Ubound(numarray) - Lbound(numarray)) + 1
'Determine the number of elements in the array
uppelts = Ubound(numarray)
For i = lowelts To uppelts
total = total + numarray(i)
Next i
avg = total / (numelts)
For i = lowelts To uppelts
diff = Abs(numarray(i) - avg)
Messagebox "The difference between the number: " & Cstr(numarray(i)) & " the average: " & Cstr(avg) & " is: " & Cstr(diff)
Next i
Messagebox "Number of elements = " & Cstr(numelts)
Messagebox "Total = " & Cstr(total)

Messagebox "Average = " & Cstr(avg)
End Sub