请教:想把在text1中生成的10个随机数(以空格隔开)按升序排列后在text2中显示,用vb怎样写?谢谢。
展开全部
方法之一:
Dim Mun(9) As Single
Private Sub Command1_Click() ‘生成随机数并显示
Dim I As Integer
Randomize
For I = 0 To 9
Mun(I) = Rnd
Text1.Text = Text1.Text & CStr(Mun(I)) & Space(1)
Next I
End Sub
Private Sub Command2_Click() ’排序并显示
Dim I As Integer
Dim J As Integer
Dim Swap As Single
For I = 0 To 9
For J = I + 1 To 9
If Mun(I) < Mun(J) Then
Swap = Mun(I)
Mun(I) = Mun(J)
Mun(J) = Swap
End If
Next J
Next I
For I = 0 To 9
Text2.Text = Text2.Text & CStr(Mun(I)) & vbCrLf
Next I
End Sub
Dim Mun(9) As Single
Private Sub Command1_Click() ‘生成随机数并显示
Dim I As Integer
Randomize
For I = 0 To 9
Mun(I) = Rnd
Text1.Text = Text1.Text & CStr(Mun(I)) & Space(1)
Next I
End Sub
Private Sub Command2_Click() ’排序并显示
Dim I As Integer
Dim J As Integer
Dim Swap As Single
For I = 0 To 9
For J = I + 1 To 9
If Mun(I) < Mun(J) Then
Swap = Mun(I)
Mun(I) = Mun(J)
Mun(J) = Swap
End If
Next J
Next I
For I = 0 To 9
Text2.Text = Text2.Text & CStr(Mun(I)) & vbCrLf
Next I
End Sub
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询