-
Notifications
You must be signed in to change notification settings - Fork 4
/
maxValueInArray.bas
53 lines (45 loc) · 2.02 KB
/
maxValueInArray.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
'''''''''''''''''''''''''''''''''''''''''''''''
' max '
'''''''''''''''''''''''''''''''''''''''''''''''
'recieves input of
' numbers array (ex. Array(1,3,5,9)) as single number, multiple numbers, or multiple arrays of numbers
'outputs the maximum number contained within an array
''' From The Author '''
'@Description: This function takes multiple numbers or multiple arrays of numbers and returns the max 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: =Max(1, 2, 3) -> 3
'@Example: =Max(4.4, 5, "6") -> 6
'@Example: =Max(x) -> 3; Where x is an array with these values [1, 2.2, "3"]
'@Example: =Max(x, y, 10) -> 15; Where x = [1, 2.2, "3"] and y = [5, 15, -100]
Public Function max(ParamArray numbers() As Variant) As Double
Dim individualParamArrayValue As Variant
Dim individualValue As Variant
Dim maxValue As Variant
maxValue = 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(maxValue) Then
maxValue = individualValue
ElseIf individualValue > maxValue Then
maxValue = individualValue
End If
Next
Else
If TypeName(individualParamArrayValue) = "String" Then
individualParamArrayValue = CDbl(individualParamArrayValue)
End If
If IsEmpty(maxValue) Then
maxValue = individualParamArrayValue
ElseIf individualParamArrayValue > maxValue Then
maxValue = individualParamArrayValue
End If
End If
Next
max = maxValue
End Function