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
我试试看,这个挺有用的样子啊
[此贴子已经被作者于2007-10-21 19:17:08编辑过]