# Re: 气死我了，快拉兄弟一把！

Posted by Knight on May 03, 1999 at 10:05:31:

In Reply to: 气死我了，快拉兄弟一把！ posted by 八戒 on April 28, 1999 at 01:33:41:

: 八戒刚出家，第一次来，给各位问好！

: 八戒想发□，用VB做个六合彩的?测器。用个Label array分别□示7个从1 - 49的数。但数字不能□复(repeat)，即每个数只能用一次。

: 写了段code, 不知为何，数字不□复没能实现。哪位大师给看看是什么毛病？

: The code is as following:

: Private Sub Command1_Click()
: Dim iLuckyNumber As Integer
: Dim i As Integer
: Dim j As Integer
:
: For i = 0 To 6
: Label1(i) = "" 'clear all numbers to zero at beginning"
: Next i

:
: For i = 0 To 6 'allocate numbers to 7 labels
:

--------------------------------------------
: Do While iLuckyNumber < 1 Or iLuckyNumber > 49 'number must be between 1 and 49
: iLuckyNumber = Int(Rnd * 100)
: Loop
--------------------------------------------
这段可改成
iluckynumber=int(rnd*49)+1

:
: For j = 0 To i 'compare iLuckyNumber with numbers on previous labels
: If iLuckyNumber = Val(Label1(j).Caption) Then 'if new number is the same as previous, reset i=i-1 to do it again
: i = i - 1
: End If
: Next j
:

错误在此..找到重覆的值后会将iluckynumber,放到最后一位
: Label1(i).Caption = iLuckyNumber
: iLuckyNumber = 0
:
: Next i
: Randomize
randomize这个要拿到前面不然每次run的第一次内容都相同
:
: End Sub

Follow Ups: