举例说明:比如自定义一个好象EXCEL里的MAX()返回做大值,可以返回N个数的最大值,也可以返回N+1个数的最大值
谢谢!
Option Explicit
Public Function Max(Optional ByVal Value) As Double
Dim x As Variant
Dim Temp As Double
Dim Temp1() As String
On Error Resume Next
If IsMissing(Value) = True Then
Exit Function
End If
If IsArray(Value) = True Then ''''''''(1)如果Value为数组'''''''
Temp = Value(LBound(Value))
For Each x In Value
If x > Temp Then
Temp = x
End If
Next
ElseIf VarType(Value) = vbString Then '''''(2)如果value为字符串''''''''
Temp1 = Split(Value, ",")
Temp = Temp1(LBound(Temp1))
For Each x In Temp1
If x > Temp Then
Temp = x
End If
Next
End If
Max = Temp
End Function
Private Sub Command1_Click()
Dim Value(4) As Double
Value(0) = -100.5
Value(1) = 9.56325
Value(2) = -20
Value(3) = 100.284
Value(4) = -30.5
Text2 = Max(Value)
End Sub
Private Sub Text1_Change()
Text2 = Max(Text1)
End Sub