急!!!VB高手帮我做一下作业!!谢谢!!

2024-12-31 00:39:53
推荐回答(1个)
回答1:

三个文本框,三个命令按钮
Dim arr() As Integer
Private Sub Command1_Click()
ReDim arr(19)
Text1.Text = ""
Randomize
For i = 0 To 19
arr(i) = Int(Rnd * 50) + 1
Text1.Text = Text1.Text & arr(i) & ","
Next i
End Sub

Private Sub Command2_Click()
Text2.Text = ""
For i = 0 To 19
For j = 19 To i + 1 Step -1
If arr(j) < arr(j - 1) Then
t = arr(j): arr(j) = arr(j - 1): arr(j - 1) = t
End If
Next j
Text2.Text = Text2.Text & arr(i) & ","
Next i
End Sub

Private Sub Command3_Click()
Dim n As Integer
ReDim Preserve arr(20)
n = InputBox("输入")
For i = 19 To 0 Step -1
If arr(i) > n Then
arr(i + 1) = arr(i)
Else
Exit For
End If
Next i
arr(i + 1) = n
Text3.Text = ""
For i = 0 To 20
Text3.Text = Text3.Text & arr(i) & ","
Next i
End Sub