编制求两数中的较大数的FUNCTION函数,并推广到求多个数的较大数

来源:百度知道 编辑:UC知道 时间:2024/05/16 14:52:18

Private Sub Command1_Click()
s = Split(Text1.Text, ",")
For i = 0 To UBound(s) - 1
ss = Comp(s(i), s(i + 1))
Next
Label1.Caption = ss
End Sub

Private Function Comp(s1, s2)
If Int(s1) > Int(s2) Then
Comp = s1
Else
Comp = s2
End If
End Function

Function KeepMax(ClrMem As Boolean, Num As Double) As Double
Static Mem As Double
If ClrMem Then Mem = 0: Exit Function
Mem = IIf(Mem < Num, Num, Mem)
KeepMax = Mem
End Function
'测试代码
Private Sub Command1_Click()
Dim test(9) As Double
test(0) = 50
test(2) = 79.0000001
test(3) = -80
test(4) = 60
test(5) = 36
test(6) = 55
test(7) = -73
test(8) = 79
test(9) = 44
Call KeepMax(True, 0)
For i = 0 To 9
aaa = KeepMax(False, test(i))
Next
MsgBox aaa
End Sub