一.输出五个随机数
1点击“CommandButton”按钮,再在右侧Form1中空白区域选择大小适宜的区域,出现按钮型图标。
2选中图标,在右下角,将表格中“Caption”后面的“Command1”改成“输出”。
3双击按钮型图标,输入如下.
Private Sub Command1_Click()
Cls
Dim n As Integer
Dim a(5) As Integer
n = 1
While n <= 5
a(n) = Int(Rnd * 1000)
n = n + 1
Wend
n = 1
While n <= 5
Print a(n)
n = n + 1
Wend
End Sub
1点击“CommandButton”按钮,再在右侧Form1中空白区域选择大小适宜的区域,出现按钮型图标。
2选中图标,在右下角,将表格中“Caption”后面的“Command1”改成“输出”。
3双击按钮型图标,输入如下.
Private Sub Command1_Click()
Cls
Dim n As Integer
Dim a(5) As Integer
n = 1
While n <= 5
a(n) = Int(Rnd * 1000)
n = n + 1
Wend
n = 1
While n <= 5
Print a(n)
n = n + 1
Wend
End Sub
二.排序五个随机数
1点击“CommandButton”按钮,再在右侧Form1中空白区域选择大小适宜的区域,出现按钮型图标。
2选中图标,在右下角,将表格中“Caption”后面的“Command1”改成“排序”。
3双击按钮型图标,输入如下.
Private Sub Command1_Click()
Cls
Dim n As Integer
Dim a(5) As Integer
n = 1
While n <= 5
a(n) = Int(Rnd * 1000)
n = n + 1
Wend
Dim t As Integer, m As Integer
m = 1
While m <= 4
n = 1
While n <= 5 - m
If a(n) < a(n + 1) Then
t = a(n): a(n) = a(n + 1): a(n + 1) = t
End If
n = n + 1
Wend
m = m + 1
Wend
n = 1
While n <= 5
Print a(n)
n = n + 1
Wend
End Sub
1点击“CommandButton”按钮,再在右侧Form1中空白区域选择大小适宜的区域,出现按钮型图标。
2选中图标,在右下角,将表格中“Caption”后面的“Command1”改成“排序”。
3双击按钮型图标,输入如下.
Private Sub Command1_Click()
Cls
Dim n As Integer
Dim a(5) As Integer
n = 1
While n <= 5
a(n) = Int(Rnd * 1000)
n = n + 1
Wend
Dim t As Integer, m As Integer
m = 1
While m <= 4
n = 1
While n <= 5 - m
If a(n) < a(n + 1) Then
t = a(n): a(n) = a(n + 1): a(n + 1) = t
End If
n = n + 1
Wend
m = m + 1
Wend
n = 1
While n <= 5
Print a(n)
n = n + 1
Wend
End Sub
三.x个随机数排序
1点击“Text”文本框图标,再在右侧Form1中空白区域选择大小适宜的区域,画出文本框。
2点击“CommandButton”按钮,再在右侧Form1中空白区域选择大小适宜的区域,出现按钮型图标。
3选中图标,在右下角,将表格中“Caption”后面的“Command1”改成“输出排序”。
4双击按钮型图标,输入如下.
Option Base 1
Private Sub Command1_Click()
Cls
Dim n As Integer, x As Integer
x = Int(Val(Me.Text1.Text))
Dim a() As Integer
ReDim a(x)
n = LBound(a)
While n <= UBound(a)
a(n) = Int(Rnd * 1000)
n = n + 1
Wend
Dim m As Integer, t As Integer
m = LBound(a)
While m <= UBound(a) - 1
n = LBound(a)
While n <= UBound(a) - m
If a(n) < a(n + 1) Then
t = a(n): a(n) = a(n + 1): a(n + 1) = t
End If
n = n + 1
Wend
m = m + 1
Wend
n = LBound(a)
While n <= UBound(a)
Print a(n)
n = n + 1
Wend
End Sub
1点击“Text”文本框图标,再在右侧Form1中空白区域选择大小适宜的区域,画出文本框。
2点击“CommandButton”按钮,再在右侧Form1中空白区域选择大小适宜的区域,出现按钮型图标。
3选中图标,在右下角,将表格中“Caption”后面的“Command1”改成“输出排序”。
4双击按钮型图标,输入如下.
Option Base 1
Private Sub Command1_Click()
Cls
Dim n As Integer, x As Integer
x = Int(Val(Me.Text1.Text))
Dim a() As Integer
ReDim a(x)
n = LBound(a)
While n <= UBound(a)
a(n) = Int(Rnd * 1000)
n = n + 1
Wend
Dim m As Integer, t As Integer
m = LBound(a)
While m <= UBound(a) - 1
n = LBound(a)
While n <= UBound(a) - m
If a(n) < a(n + 1) Then
t = a(n): a(n) = a(n + 1): a(n + 1) = t
End If
n = n + 1
Wend
m = m + 1
Wend
n = LBound(a)
While n <= UBound(a)
Print a(n)
n = n + 1
Wend
End Sub