Private Type MType value As Variant locate As Integer End Type Private Sub Form_Load() Dim a(7) As Integer a(0) = 1 a(1) = 8 a(2) = 1 a(3) = 8 a(4) = 4 a(5) = 3 a(6) = 9 a(7) = 1 Dim m As MType m = MaxValue(a) MsgBox "最大值是:" & m.value & " 位置是:" & m.locate End Sub Private Function MaxValue(ByVal arr As Variant) As MType Dim i As Integer Dim max As MType max.value = arr(LBound(arr)) max.locate = LBound(arr) For i = LBound(arr) To UBound(arr) If arr(i) > max.value Then max.value = arr(i) max.locate = i End If Next MaxValue = max End Function |
|