Attribute VB_Name = "Loops"
' Visustin demo module
' Demonstrates flowcharting of loops

Function Sum(ParamArray Values())
 ' Return the sum of values passed to this function
 ' Sum("a","b","c") returns "abc"
 ' Sum(-10, -100)   returns -110

 ' Iterate over all Values
 For i = LBound(Values) To UBound(Values)
  ' Add each value to Total
  Total = Total + Values(i)
 Next

 ' Return the total
 Sum = Total

End Function

Function Min(ParamArray Values())
 ' Return the smallest value passed to this function
 ' Min("a","b","c") returns "a"
 ' Min(-10, -100)   returns -100
 ' Example of Do While .. Loop

 ' Let i be the first index
 i = LBound(Values, 1)

 Min = Values(i) ' Store the first value

 ' Compare all values to Min except the first one
 Do While i < UBound(Values, 1)
  i = i + 1
  If Min > Values(i) Then Min = Values(i)
 Loop

End Function



Function Max(ParamArray Values())
 ' Return the largest value passed to this function
 ' Max("a","b","c") returns "c"
 ' Max(-10, -100)   returns -10
 ' Example of Do .. Loop Until

 Max = Values(UBound(Values, 1)) ' Store the last value

 ' Compare all values to Max
 ' starting with the first value
 i = LBound(Values, 1)

 Do
  If Max < Values(i) Then Max = Values(i)
  i = i + 1
 Loop Until i >= UBound(Values, 1) ' Can quit without comparing the last value

End Function