猜數字

Dim a(3) As Integer
Dim gst(3) As Integer
Dim ttimes As Integer


Private Sub Command1_Click()


For i = 0 To 3
a(i) = Int(Rnd * 7) + 1


If i > 0 Then

For j = 0 To i - 1
If a(j) = a(i) Then
i = i - 1
Exit For
End If
Next j

End If

Next i
List1.Clear
ttimes = 0
Text1.Text = ""
End Sub


Private Sub Command2_Click()
Dim aa, bb As Integer

aa = 0
bb = 0
If Len(Text1.Text) <> 4 Then
MsgBox "
必須輸入4位不重複的數字!", vbOKOnly + vbInformation, "猜數字遊戲"
Text1.Text = ""
Exit Sub
End If
For i = 1 To 4
gst(i - 1) = Val(Mid(Text1.Text, i, 1))
Next i

For i = 1 To 3
For j = 0 To i - 1
If gst(i) = gst(j) Then
MsgBox "
數字有重複!", vbOKOnly + vbInformation, "猜數字遊戲"
Text1.Text = ""
Exit Sub
End If
Next j
Next i

For x = 0 To 3
If a(x) = gst(x) Then
aa = aa + 1
Else
For y = 0 To 3
If y <> x And a(x) = gst(y) Then bb = bb + 1
Next y
End If
Next x

ttimes = ttimes + 1
List1.AddItem Text1.Text & " " & aa & "A" & bb & "B
" & ttimes & ""

If aa = 4 Then
Select Case ttimes
Case 1 To 10: ss = "very good!"
Case 11 To 10: ss = "not bad!"
Case 21 To 30: ss = "I'm waitting for a long time"
Case Else: ss = "right but it's too deep"
End Select
MsgBox ss, vbOKOnly + vbInformation, "
猜數字遊戲"
Call Command1_Click
Else
MsgBox aa & "A" & bb & "B", vbOKOnly + vbInformation, "
猜數字遊戲"
End If

End Sub
Private Sub form_load()
Call Command1_Click
End Sub
Private Sub text1_keypress(keyascii As Integer)
If Not (keyascii >= 48 And keyascii <= 57) And keyascii <> 8 Then _
keyascii = 0
End Sub

 

 

 

 

樂透選號

Dim a(6) As Integer
Dim t As Integer

Private Sub Command1_Click()
Timer1.Enabled = True
t = 0

For m = 0 To 5
a(m) = 0

Next m

For i = 0 To 5

Randomize

a(i) = Int(Rnd * 40) + 1
If i > 0 Then

For j = 0 To i - 1

If a(j) = a(i) Then
i = i - 1
Exit For
End If
Next j
End If
Next i
End Sub


Private Sub Command2_Click()
For x = 0 To 5
Label1(x).Caption = ""
Text1(x).ForeColor = RGB(0, 0, 0)
Next x

End Sub






Private Sub Timer1_Timer()
t = t + 1
Label3.Caption = Int(Rnd * 42) + 1


If t = 5 Then
Label3.Caption = a(0)
Label1(0).Caption = a(0)

Call showColor(a(0))
End If

If t = 10 Then
Label3.Caption = a(1)
Label1(1).Caption = a(1)

Call showColor(a(1))
End If

If t = 15 Then
Label3.Caption = a(2)
Label1(2).Caption = a(2)

Call showColor(a(2))
End If

If t = 20 Then
Label3.Caption = a(3)
Label1(3).Caption = a(3)

Call showColor(a(3))
End If

If t = 25 Then
Label3.Caption = a(4)
Label1(4).Caption = a(4)

Call showColor(a(4))
End If

If t = 30 Then
Label3.Caption = a(5)
Label1(5).Caption = a(5)

Call showColor(a(5))



Timer1.Enabled = False

MsgBox "
開獎完畢"


End If
End Sub

Sub showColor(luckyNo As Integer)
For y = 0 To 5
If Val(Text1(y).Text) = luckyNo Then
Text1(y).ForeColor = RGB(255, 0, 0)
End If
Next y

End Sub

 

 

樂透

Dim a(6) As Integer
Dim t As Integer

Private Sub command1_click()

'
啟動yimer
Timer1.Enabled = True

t = 0

For i = 0 To 5
'
產生1~42的亂數
a(i) = Int(Rnd * 42) + 1
If i > 0 Then
'
檢查亂數是否重複
For j = 0 To i - 1
If a(j) = a(i) Then '
如果重複,i-1,且跳出For
i = i - 1
Exit For
End If
Next j
End If
Next i


End Sub

Private Sub Command2_Click()
'
清除所有開獎數字
Label1(0).Caption = ""
Label1(1).Caption = ""
Label1(2).Caption = ""
Label1(3).Caption = ""
Label1(4).Caption = ""
Label1(5).Caption = ""


End Sub

Private Sub Timer1_Timer()
'
計算時間延遲
t = t + 1
'
顯示開獎機的滾動數字(其實數字已開出來,這裡只是騙使用者的)
Label3.Caption = Int(Rnd * 42) + 1

'
依序顯示數字(5個時間單位,t=5,10,15...)
If t = 5 Then
Label3.Caption = a(0)
Label1(0).Caption = a(0)
End If

If t = 10 Then
Label3.Caption = a(1)
Label1(1).Caption = a(1)
End If

If t = 15 Then
Label3.Caption = a(2)
Label1(2).Caption = a(2)
End If

If t = 20 Then
Label3.Caption = a(3)
Label1(3).Caption = a(3)
End If

If t = 25 Then
Label3.Caption = a(4)
Label1(4).Caption = a(4)
End If

If t = 30 Then
Label3.Caption = a(5)
Label1(5).Caption = a(5)

'
關閉時間控制器
Timer1.Enabled = False
'
顯示開獎完畢訊息
MsgBox "
開獎完畢!"
End If
End Sub

 

 

Hosted by www.Geocities.ws

1