上面都只实现了随机八位数,没有判断是否重复!
Private Sub Command1_Click()
Dim s As String
Dim a(0 To 9) As Boolean
For i = 0 To 9
a(i) = True
Next
Randomize
Do
s = Int(9 * Rnd + 1)
If a(s) = True Then
Text1.Text = Text1.Text & Trim(Str(s))
a(s) = False
i = Val(Len(Trim(Text1.Text)))
End If
Loop While i < 8
End Sub
next i
Private Sub Command1_Click()
Dim s As Integer
Dim s1 As String
Dim a(0 To 9) As Boolean
For i = 0 To 9
a(i) = True
Next
Randomize
Do
s = Int(9 * Rnd + 1)
If a(s) = True Then
s1 = s1 & Trim(Str(s))
a(s) = False
i = Val(Len(Trim(s1)))
End If
Loop While i < 8
Text1.Text = s1
End Sub
刚刚那个有点小BUG呵呵
如果是8位数,那么最高位为"0"的数还没有判断,你可以根据自己的要求 增加一行判断就行了!