I am using the following code
Please tell me whats wrong here in.
nd any alternative for it.

Basically i want to get max no of an array through a function.
nd i m passing an array to the function "Max".
it gives me error "Subscript out of range"
can i pass an array as Argument(Parameter) to a function.
If yes then How?



Code:
Dim ar() As Integer
Private Sub Command1_Click()
Dim i As Integer ''Holds array length
i = InputBox("Enter Total elements")
For j = 0 To i
	ReDim Preserve ar(j)
	ar(j) = InputBox("Enter the Nos to GetMax Value Of")
Next
MsgBox max(ar())
End Sub
 

Public Function max(ParamArray a()) As Integer
Dim temp As Integer
For b = 0 To UBound(a())
	If a(b) > a(b + 1) Then			  <==Error Here
		temp = a(b)
	Else
		temp = a(b + 1)
	End If
Next
max = temp
End Function
Thanks in Adv.