vb随机数排序问题1.随机产生10个[
新建 Form1 ,添加 Label1 , Label2 和 Command1 ,复制以下代码:
Private Sub Command1_Click()
Form_Load
Dim a(1 To 10) As Integer, m As Integer
Randomize
For i = 1 To 10
a(i) = Int(Rnd * 100 + 1)
Label1。 Caption = Label1。Caption + " " & a(i)
Next i
x = MsgBox("单击“是”选择升序,单击“否”选择降序。", vbYesNo + vbInformation, "排序"...全部
新建 Form1 ,添加 Label1 , Label2 和 Command1 ,复制以下代码:
Private Sub Command1_Click()
Form_Load
Dim a(1 To 10) As Integer, m As Integer
Randomize
For i = 1 To 10
a(i) = Int(Rnd * 100 + 1)
Label1。
Caption = Label1。Caption + " " & a(i)
Next i
x = MsgBox("单击“是”选择升序,单击“否”选择降序。", vbYesNo + vbInformation, "排序")
If x = vbYes Then
m = 100
Label2。
Caption = "排序结果(升序):"
For j = 1 To 10
For i = 1 To 10
If a(i) = m Then m = a(i)
Next i
For i = 1 To 10
If a(i) = m Then
Label2。
Caption = Label2。Caption + " " & a(i)
a(i) = 0
End If
Next i
m = 1
Next j
End If
Open "c:\result。
txt" For Output As #1
Write #1, Label2。Caption
Close #1
MsgBox "结果已经输出到 c:\result。txt 。", vbOKOnly + vbInformation, "结果"
End Sub
Public Sub Form_Load()
Label1。
AutoSize = True
Label2。AutoSize = True
Label1。Caption = "自然数:"
Label2。Caption = "排序结果:"
Command1。
Caption = "&Done"
End Sub。收起