VB中从0000000--9999999中的随机整数,而且还要不得与TXT 文件中存在的若干条记录数字相同

来源:百度知道 编辑:UC知道 时间:2024/05/11 00:08:04
我是想做个体育彩票的数据产生程序,(主要是自己玩玩)。TXT文件中保存的是历史开奖数据,七位数。程序主要是分析TXT中所有的数据后产生一个与TXT中不重复的随机数。 txt中的文件是一行一个,
1234567
7654321
2234566
.....
如此!
希望高手能够解答下。谢谢!

Private Sub Command1_Click()
Dim strTem As String
Dim intTem As Integer
Dim sName() As String
Dim i As Integer
Dim j As Integer
Dim iTemp As Integer
Dim aa As Integer

Do
intTem = Int(Rnd * (34 - 1)) + 1

If InStr(1, strTem, CStr(intTem)) = 0 Then
strTem = strTem + CStr(intTem) + "."
i = i + 1
If i > 5 Then Exit Do
End If
Loop

sName() = Split(strTem, ".")

For i = 0 To UBound(sName()) - 1
For j = 0 To i - 1
If Val(sName(j)) > Val(sName(j + 1)) Then
iTemp = sName(j)
sName(j) = sName(j + 1)
sName(j + 1) = iTemp
End If
Next
Next

For i = 0 To UBound(sName()) - 1
Text1(i).Text = Format(sName(i), "00")
Next

Text2.Text = Int(Rnd * (17 - 1)) + 1

aa = Val(Text1(0).Text) + _
Val(Text1(1).Text)