View Single Post
  #5   Report Post  
Posted to microsoft.public.excel.misc
Dave Peterson Dave Peterson is offline
external usenet poster
 
Posts: 35,218
Default error in programme

You didn't put anything in a().

You could let excel do the heavy lifting for you, too:

Option Explicit
Sub testing2()
Dim a(1 To 100) As Double
Dim max As Double
Dim min As Double
Dim sum As Double
Dim Average As Double
Dim i As Long

'put some stuff in that array
For i = LBound(a) To UBound(a)
a(i) = Rnd
Next i

With Application
max = .max(a)
min = .min(a)
sum = .sum(a)
Average = .Average(a)

End With

MsgBox "max = " & max & vbLf _
& "min = " & min & vbLf _
& "sum = " & sum & vbLf _
& "average = " & Average

End Sub


biker man wrote:

the programme i wrote is to return the maximum, minimum and average
of
100 numbers. But it keeps returning an error. Does anyone no whats
wrong with it? what its missing?
cheers

Sub testing()
Dim a(10) As Single, max As Single
Dim min As Single, sum As Single
Dim Average As Integer, i As Integer
n = 100
max = a(1)
min = a(1)
sum = a(1)
For i = 1 To 100
If max a(i) Then max = a(i)
If min < a(i) Then
min = a(i)
End If
sum = sum + a(i)
Next i
Average = sum / n
End Sub


--

Dave Peterson