'1、在名称为Form1,标题为“数组为参数”的窗体上有两个命令按钮C1,C2,标题分别为”输入显示”,“退出”;
'2、两个文本框Text1,Text2,初始内容为空,两个标签L1,L2,标题为标题分别为“数组中的最大值”和“数组中的最小值”。
'3、在Text1和Text2中分别显示出最大值和最小值。单击C2退出程序。
Private Sub C1_Click()
Dim array1(0 To 19) As Double
Dim a As Double
Dim b As Double
For i = 0 To 19
array1(i) = Val(InputBox("输入数值"))
Next i
Call max(array1, a, b)
Text1 = a
Text2 = b
End Sub
Private Sub C2_Click()
Unload Me
End Sub
Private Sub Form_Load()
Me.Caption = "数组为参数"
Text1 = ""
Text2 = ""
L1.Caption = "数组中的最大值"
L2.Caption = "数组中的最小值"
C1.Caption = "输入显示"
C2.Caption = "退出"
End Sub
Sub max(array1, a, b)
For i = 0 To UBound(array1) - 1
For j = UBound(array1) - 1 To i Step -1
If array1(j) > array1(j + 1) Then
a = array1(j)
array1(j) = array1(j + 1)
array1(j + 1) = a
End If
Next j
Next i
a = array1(UBound(array1))
b = array1(0)
End Sub
温馨提示:答案为网友推荐,仅供参考