VB编程随机选数不重复问题和刷新问题
我做了道福利彩票VB小程序!
要求选的六个数必须没有重复的!
但有时侯有两个数字是完全一样的!
而且关掉程序之后,再打开该程序,结果出现的结果还和第一次一模一样!
刷新问题如何解决?
随机选数问题?
如何使输入的数字没有重复?
请看代码:
Private Sub Command1_Click()
Dim a(6) As Integer
Dim i As Integer, j As Integer
c = Int(16 * Rnd) + 1
Text1.Text = CStr(c)
For i = 1 To 6
a(i) = Int((33 - 1 + 1) * Rnd) + 1
Next i
Call s(a)
For i = 1 To 6
Text2(i - 1).Text = CStr(a(i))
Next i
End Sub
Private Sub s(m() As Integer)
Dim i As Integer, j As Integer
Dim t As Integer
For i = 0 To UBound(m) - 1
For j = i + 1 To UBound(m)
If m(i) > m(j) Then
t = m(i)
m(i) = m(j)
m(j) = t
End If
Next j
Next i
End Sub
通过比较子程序实现了顺序排列,但仍然没有实现重复数字的消除!
刷新也没有解决!
请修改之!
谢谢!