-
Notifications
You must be signed in to change notification settings - Fork 4
/
minValueInArray.bas
55 lines (46 loc) · 2.05 KB
/
minValueInArray.bas
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
'''''''''''''''''''''''''''''''''''''''''''''''
' min '
'''''''''''''''''''''''''''''''''''''''''''''''
'recieves input of
' numbers array (ex. "foo") as single number, multiple numbers, or multiple arrays of numbers
'outputs the minimum number contained within an array
''' From The Author '''
'@Description: This function takes multiple numbers or multiple arrays of numbers and returns the min number. This function also accounts for numbers that are formatted as strings by converting them into numbers
'@Author: Anthony Mancini
'@Version: 1.0.0
'@License: MIT
'@Example: =Min(1, 2, 3) -> 1
'@Example: =Min(4.4, 5, "6") -> 4.4
'@Example: =Min(-1, -2, -3) -> -3
'@Example: =Min(x) -> 1; Where x is an array with these values [1, 2.2, "3"]
'@Example: =Min(x, y, 10) -> -100; Where x = [1, 2.2, "3"] and y = [5, 15, -100]
Public Function min(ParamArray numbers() As Variant) As Double
Dim individualParamArrayValue As Variant
Dim individualValue As Variant
Dim minValue As Variant
minValue = Empty
For Each individualParamArrayValue In numbers
If IsArray(individualParamArrayValue) Then
For Each individualValue In individualParamArrayValue
If TypeName(individualValue) = "String" Then
individualValue = CDbl(individualValue)
End If
If IsEmpty(minValue) Then
minValue = individualValue
ElseIf individualValue < minValue Then
minValue = individualValue
End If
Next
Else
If TypeName(individualParamArrayValue) = "String" Then
individualParamArrayValue = CDbl(individualParamArrayValue)
End If
If IsEmpty(minValue) Then
minValue = individualParamArrayValue
ElseIf individualParamArrayValue < minValue Then
minValue = individualParamArrayValue
End If
End If
Next
min = minValue
End Function