3个回答
2013-07-14
展开全部
新建一个单窗体的工程,在上面画出七个TEXTBOX,最好是一个控件数组,这样编程时容易控制,再建一个COMMOND BUTTON,将CAPTION改为“随机产生”。在程序运行后,每点击一下COMMAND1,将随机产生一组数字并按从小到大的顺序显示在文本框中。下面就是程序部分: Dim NumArray(1 To 7) As Integer′通用中定义
Private Sub Command1_Click()
Dim i, j, N As Integer
For i = 1 To 7
NumArray(i) = 0
Next i
Randomize
NumArray(1) = Fix(1 + 32 * (Rnd()))
j = 1
Do
N = Fix(1 + 32 * (Rnd()))
For i = 1 To j
If N = NumArray(i) Then
Exit For ′重复时
ElseIf i = j Then ′未重复时
NumArray(i + 1) = N
j = j + 1
Exit For
End If
Next i
Loop While j < 7
PopSort ′升序排列
For i = 1 To 7
Text1(i - 1).Text = NumArray(i)
Next i
End Sub
Private Sub PopSort() ′气泡排序法
Dim i, j, Temp As Integer
For i = 7 To 2 Step -1
For j = 7 - 1 To 1 Step -1
If i >= 7 - j + 1 Then
If NumArray(j + 1) < NumArray(j) Then
Temp = NumArray(j)
NumArray(j) = NumArray(j + 1)
NumArray(j + 1) = Temp
End If
End If
Next j
Next i
End Sub
Private Sub Command1_Click()
Dim i, j, N As Integer
For i = 1 To 7
NumArray(i) = 0
Next i
Randomize
NumArray(1) = Fix(1 + 32 * (Rnd()))
j = 1
Do
N = Fix(1 + 32 * (Rnd()))
For i = 1 To j
If N = NumArray(i) Then
Exit For ′重复时
ElseIf i = j Then ′未重复时
NumArray(i + 1) = N
j = j + 1
Exit For
End If
Next i
Loop While j < 7
PopSort ′升序排列
For i = 1 To 7
Text1(i - 1).Text = NumArray(i)
Next i
End Sub
Private Sub PopSort() ′气泡排序法
Dim i, j, Temp As Integer
For i = 7 To 2 Step -1
For j = 7 - 1 To 1 Step -1
If i >= 7 - j + 1 Then
If NumArray(j + 1) < NumArray(j) Then
Temp = NumArray(j)
NumArray(j) = NumArray(j + 1)
NumArray(j + 1) = Temp
End If
End If
Next j
Next i
End Sub
2013-07-14
展开全部
Private Sub Command1_Click()
Dim i, a(34), b(7)
Randomize: Cls
For i = 1 To 7
b(i) = Int(Rnd * 34 + 1)
If a(b(i)) Then i = i - 1 Else a(b(i)) = 1
Next
Print "34 选 7组 福利彩票系统,中奖号码:"
For i = 1 To 7
Print b(i)
Next
End Sub
Dim i, a(34), b(7)
Randomize: Cls
For i = 1 To 7
b(i) = Int(Rnd * 34 + 1)
If a(b(i)) Then i = i - 1 Else a(b(i)) = 1
Next
Print "34 选 7组 福利彩票系统,中奖号码:"
For i = 1 To 7
Print b(i)
Next
End Sub
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
2013-07-14
展开全部
要打包吗
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询