2个回答
展开全部
Dim AA(1 To 10) As Integer, ZGCJ(1 To 10) As Integer, ZDCJ(1 To 10) As Integer
在通用部分声明三个数组
Private Sub Command1_Click()
Text1.Text = "": Text2.Text = "": Text3.Text = ""
Text1.Text = "系统自动生成的十个数:" & vbCrLf
For I = 1 To 10
AA(I) = 0: ZGCJ(I) = 0: ZDCJ(I) = 0
Randomize
AA(I) = Int(Rnd * 90 + 10)
Text1.Text = Text1.Text & AA(I) & Space(4)
If I Mod 5 = 0 Then Text1.Text = Text1.Text & vbCrLf
ZGCJ(I) = AA(I)
ZDCJ(I) = AA(I)
Next I
End Sub
生成十个数的代码
Private Sub Command2_Click()
Text2.Text = "": Text3.Text = ""
Dim AAA As Integer, BBB As Integer
For I = 1 To 9
For J = I + 1 To 10
If ZGCJ(I) < ZGCJ(J) Then
AAA = ZGCJ(I)
ZGCJ(I) = ZGCJ(J)
ZGCJ(J) = AAA
End If
If ZDCJ(J) < ZDCJ(I) Then
BBB = ZDCJ(J)
ZDCJ(J) = ZDCJ(I)
ZDCJ(I) = BBB
End If
Next J
Next I
Text2.Text = Text2.Text & "从大到小排列:" & vbCrLf
For I = 1 To 10
Text2.Text = Text2.Text & ZGCJ(I) & Space(4)
If I Mod 5 = 0 Then Text2.Text = Text2.Text & vbCrLf
Next I
Text3.Text = Text3.Text & "从小到大排列:" & vbCrLf
For I = 1 To 10
Text3.Text = Text3.Text & ZDCJ(I) & Space(4)
If I Mod 5 = 0 Then Text3.Text = Text3.Text & vbCrLf
Next I
End Sub
排序的代码。
如果需要自己输入数字,可以这样:
'如果要自己输入数字,可以修改下面的代码
Text1.Text = "": Text2.Text = "": Text3.Text = ""
Text1.Text = "系统自动生成的十个数:" & vbCrLf
For I = 1 To 10
AA(I) = 0: ZGCJ(I) = 0: ZDCJ(I) = 0
Randomize
AA(I) = Int(Rnd * 90 + 10)
Text1.Text = Text1.Text & AA(I) & Space(4)
If I Mod 5 = 0 Then Text1.Text = Text1.Text & vbCrLf
ZGCJ(I) = AA(I)
ZDCJ(I) = AA(I)
Next I
'----------------------------修改为:
Text1.Text = "": Text2.Text = "": Text3.Text = ""
Text1.Text = "用户输入的十个数:" & vbCrLf
For I = 1 To 10
AA(I) = 0: ZGCJ(I) = 0: ZDCJ(I) = 0
AA(I) = Val(InputBox("请输入第" & I & "个数!"))
Text1.Text = Text1.Text & AA(I) & Space(4)
If I Mod 5 = 0 Then Text1.Text = Text1.Text & vbCrLf
ZGCJ(I) = AA(I)
ZDCJ(I) = AA(I)
Next I
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询