Option Explicit
Dim myvalue(19) As Integer
Private Sub Command1_Click() '单击按钮开始冒泡法
Dim i As Integer, y As Integer, temp As Integer
For i = 0 To 18
For y = i + 1 To 19
If myvalue(i) > myvalue(y) Then
temp = myvalue(i)
myvalue(i) = myvalue(y)
myvalue(y) = temp
End If
Next y
Next i
Label1.Caption = myvalue(0) '最小值
Label2.Caption = myvalue(19) '最大值
End Sub
Private Sub Command2_Click() '单击清空
Label1.Caption = ""
Label2.Caption = ""
Label3.Caption = ""
Label4.Caption = ""
End Sub
Private Sub Command3_Click() '单击产生随机数
Dim i As Integer
Randomize
For i = 0 To 19
myvalue(i) = Int((90 * Rnd) + 10) '随机产生20~99的整数
Label3.Caption = Label3.Caption & myvalue(i) & "," '列出所有的数
Next i
End Sub
Private Sub Command4_Click() '单击产生相邻的最大差值
Dim i As Integer, a As Integer, b As Integer
b = 0
For i = 0 To 18
a = myvalue(i) - myvalue(i + 1)
If a > b Then b = a
Next i
Label4.Caption = b
End Sub