Nejvyšší hodnota pole

Funkce:
'Parametry FIRST a LAST indikují, kterou část pole zpracovat. 
'Pokud nejsou zadány, bere se celé pole. 
'Pokud je vložena proměnná pro MAXINDEX,
'funkce jí přiřadí hodnotu indexu největšího elementu
 

Function ArrayMax(arr As Variant, Optional ByVal First As Variant, _ 
   Optional ByVal Last As Variant, _
   Optional MaxIndex As Long) As Variant 

   Dim Index As Long 

   If IsMissing(First) Then First = LBound(arr) 
   If IsMissing(Last) Then Last = UBound(arr) 

   ArrayMax = arr(First) 
   MaxIndex = First 

   For Index = First + 1 To Last 
      If ArrayMax < arr(Index) Then 
         ArrayMax = arr(Index) 
         MaxIndex = Index 
      End If 
   Next 

End Function

Zpět

Autor: The Bozena