forked from VlaBst6/libs
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCLowest.cls
More file actions
82 lines (67 loc) · 1.99 KB
/
CLowest.cls
File metadata and controls
82 lines (67 loc) · 1.99 KB
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
VERSION 1.0 CLASS
BEGIN
MultiUse = -1 'True
Persistable = 0 'NotPersistable
DataBindingBehavior = 0 'vbNone
DataSourceBehavior = 0 'vbNone
MTSTransactionMode = 0 'NotAnMTSObject
END
Attribute VB_Name = "CLowest"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = True
Attribute VB_PredeclaredId = False
Attribute VB_Exposed = False
Public allowNeg As Boolean
Public allowZero As Boolean
Public selIndex As Long
Public errorReturn As Long
Private Const MAX_LONG As Long = 2147483647
'note: if you pass in an array() dont utilize the paramarray() and submit multiple
' you actually can, but dont expect selIndex to work..
'maxlong = error basically..
Function lowest(ParamArray vals())
Dim tmp As Long, i As Long
tmp = MAX_LONG
selIndex = -1
If allowNeg Then allowZero = True
For Each x In vals
If IsArray(x) Then
For Each xx In x
setIfLowest xx, tmp, i
i = i + 1
Next
Exit For
Else
setIfLowest x, tmp, i
i = i + 1
End If
Next
'in case the user has changed the errorReturn to something they desire..
If tmp = MAX_LONG Then tmp = errorReturn
lowest = tmp
End Function
Private Sub setIfLowest(curVal, ByRef curLow, index As Long)
If curVal < 0 Then
If allowNeg Then
If curVal < curLow Then
curLow = curVal
selIndex = index
End If
End If
ElseIf curVal = 0 Then
If allowZero Then
If curVal < curLow Then
curLow = curVal
selIndex = index
End If
End If
Else
If curVal < curLow Then
curLow = curVal
selIndex = index
End If
End If
End Sub
Private Sub Class_Initialize()
errorReturn = MAX_LONG
End Sub