Private Sub test()
Dim i As Integer
Dim j As Integer
Dim a(10) As Integer
Dim s, s1
For i = 1 To 10
a(i) = Round(Rnd * 50, 0) + 1
For j = 1 To i - 1
If a(i) = a(j) Then
i = i - 1
End If
Next j
' Range("a" & i) = a(i) '去掉此行的第一个注释符号,此代码可在Excl的代码区运行。
s = s & "," & a(i)
Next i
MsgBox s '显示数组
M = 1
For i = 1 To 9
If a(i) >= a(i + 1) Then
If i > M Then
M = i
Else
i = M
End If
GoTo kk:
Else
x = a(i)
a(i) = a(i + 1)
a(i + 1) = x
If i <> 1 Then i = i - 2
End If
kk:
Next i
For i = 1 To 10
' Range("b" & i) = a(i) '去掉此行的第一个注释符号,此代码可在Excl的代码区运行。
s1 = s1 & "," & a(i)
Next i
MsgBox s1 '显示数组
End Sub
Dim AA(1 To 10) As Integer, BB(1 To 10) As Integer
Private Sub Command1_Click() For I = 1 To 10 BB(I) = AA(I) Next I Dim KK As Integer For I = 1 To 9 For J = 1 To 10 - I If BB(J) > BB(J + 1) Then KK = BB(J) BB(J) = BB(J + 1) BB(J + 1) = KK End If Next J Next I Text2.Text = "" For I = 1 To 10 If BB(I) < 10 Then Text2.Text = Text2.Text & "0" & CStr(BB(I)) & Space(5) Else Text2.Text = Text2.Text & CStr(BB(I)) & Space(5) End If Next I End Sub
Private Sub Command2_Click() Unload Me Form1.Show End Sub
Private Sub Form_Load() For I = 1 To 10 Randomize AA(I) = Int(Rnd * 50 + 1) Next I Text1.Text = "" For I = 1 To 10 If AA(I) < 10 Then Text1.Text = Text1.Text & "0" & CStr(AA(I)) & Space(5) Else Text1.Text = Text1.Text & CStr(AA(I)) & Space(5) End If Next I End Sub