NejkratÜφ hodnota v poli

Funkce:
'Parametry FIRST a LAST indikujφ, kterß Φßst pole se zpracuje.
'Defaultn∞ je to prvnφ a poslednφ element.
'Pokud je zadßna prom∞nnß pro SHORTESTINDEX, je vrßcena
'hodnota indexu nejdelÜφho elementu.


Function ArrShortestItem(arr As Variant, _
   Optional ByVal First As Variant, _
   Optional ByVal Last As Variant, _
   Optional ShortestIndex As Long) As Variant

   Dim index As Long
   Dim minLength As Long

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

   ArrShortestItem = arr(First)
   minLength = Len(ArrLongestItem)
   ShortestIndex = First

   For index = First + 1 To Last
      If minLength > Len(arr(index)) Then
         ArrShortestItem = arr(index)
         minLength = Len(ArrShortestItem)
         ShortestIndex = index
      End If
   Next

End Function

Zp∞t

Autor: The Bozena