VB冒泡,点击command1,随机抽取6个一位数显示到text1,点击command2对随机数排序结果显示到text2,求详解
1个回答
展开全部
Private Sub Command1_Click()
Dim i As Integer
Randomize
Text1.Text = ""
Text2.Text = ""
For i = 1 To 6
Text1.Text = Text1.Text & Int(9 * Rnd)
Next
End Sub
Private Sub Command2_Click()
Dim i As Integer, j As Integer, k As Integer, oo As String
If Len(Text1.Text) <> 6 Then Exit Sub
oo = Text1.Text
For i = 1 To 6
For j = i + 1 To 6
If Mid(oo, i, 1) > Mid(oo, j, 1) Then
k = Mid(oo, i, 1)
Mid(oo, i, 1) = Mid(oo, j, 1)
Mid(oo, j, 1) = k
End If
Next
Next
Text2.Text = oo
End Sub
Dim i As Integer
Randomize
Text1.Text = ""
Text2.Text = ""
For i = 1 To 6
Text1.Text = Text1.Text & Int(9 * Rnd)
Next
End Sub
Private Sub Command2_Click()
Dim i As Integer, j As Integer, k As Integer, oo As String
If Len(Text1.Text) <> 6 Then Exit Sub
oo = Text1.Text
For i = 1 To 6
For j = i + 1 To 6
If Mid(oo, i, 1) > Mid(oo, j, 1) Then
k = Mid(oo, i, 1)
Mid(oo, i, 1) = Mid(oo, j, 1)
Mid(oo, j, 1) = k
End If
Next
Next
Text2.Text = oo
End Sub
追问
是我弄错了不好意思啊,谢谢你的回答,很好!
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询