用VB编写一个子过程或者子函数,能够找出一个包含10个元素的整数数组的最大值和最小值

来源:百度知道 编辑:UC知道 时间:2024/06/08 10:40:41

Private Sub Form_Load()
Dim l(9) As Integer
For i = 0 To 9
l(i) = i
Next

Debug.Print GETMAXMIN(l)

End Sub
Function GETMAXMIN(a() As Integer) As String
Dim x, z
z = 0
x = 0
For i = LBound(a) To UBound(a)
If a(i) > x Then
x = a(i)
End If
Next
For j = LBound(a) To UBound(a)
If a(j) < z Then
z = a(j)
End If
Next

GETMAXMIN = "The max is " & x & Chr(13) & "The min is " & z

End Function

public function GetMaxMin(ary() as integer,minFlag as boolean) as integer
dim temp as integer
dim i as integer

temp=ary(0)

for i=1 to ubound(ary)
  if minFlag then
    if temp>ary(i) then
      temp=ary(i)
    end if
  else
    if temp<ary(i) then
 &