为什么我做的这段抽奖程序会出现cpu 100%的假死机呢?
Private Sub Timer1_Timer() Label2.Alignment = 2 Label3.Alignment = 2 Label4.Alignment = 2 If ten_flag = False Then Do num = Int(660 * Rnd + 1) num4 = num num1 = num4 Mod 10 '个位 num4 = Int(num4 / 10) num2 = num4 Mod 10 '十位 num4 = Int(num4 / 10) num3 = num4 Mod 10 '百位 Loop While tempnum(num) = 1 tempnum(num) = 1 Label4.Caption = num1 Label3.Caption = num2 Label2.Caption = num3 str_temp = Label2.Caption + Label3.Caption + Label4.Caption Else str_temp = "" For ten_i = 1 To 10 Do num = Int(660 * Rnd + 1) num4 = num num1 = num4 Mod 10 '个位 num4 = Int(num4 / 10) num2 = num4 Mod 10 '十位 num4 = Int(num4 / 10) num3 = num4 Mod 10 '百位 Loop While tempnum(num) = 1 tempnum(num) = 1 Label4.Caption = num1 Label3.Caption = num2 Label2.Caption = num3 str_temp = str_temp + Label2.Caption + Label3.Caption + Label4.Caption + " " Next ten_iEnd If
Option ExplicitPrivate priNumList() As LongPrivate priOutList() As StringPrivate Sub Form_Load() '需要设置Text1.MultiLine = True Timer1.Enabled = False Dim tIndex As Long Dim tNumCount As Long Dim tOutCount As Long tNumCount = 660 '可以把这个数字设置成10来测试它是否准确。 tOutCount = 10 ReDim priNumList(tNumCount - 1) ReDim priOutList(tOutCount - 1) For tIndex = 0 To tNumCount - 1 priNumList(tIndex) = tIndex Next Command1.Caption = "开始" Timer1.Interval = 10End SubPrivate Sub Command1_Click() '开始 Timer1.Enabled = Not Timer1.Enabled Command1.Caption = Split("开始,停止", ",")(Timer1.Enabled And 1)End SubPrivate Sub ListSwap(ByRef pList() As Long, ByRef pIndex As Long) '将pIndex指定的元素与后面的随机元素交换。 Dim tDesIndex As Long tDesIndex = Int(Rnd * (UBound(pList()) - pIndex)) + pIndex ValueSwap pList(pIndex), pList(tDesIndex)End SubPrivate Sub ValueSwap(ByRef pA As Long, ByRef pB As Long) '交换两个Long的值。 Dim tT As Long tT = pA: pA = pB: pB = tTEnd SubPrivate Sub Timer1_Timer() Dim tIndex As Long For tIndex = 0 To 9 ListSwap priNumList(), tIndex priOutList(tIndex) = Format(tIndex + 1, "00") & " " & Format(priNumList(tIndex), "000") Next Text1.Text = Join(priOutList, vbCrLf)End Sub