?? guessform.frm
字號:
VERSION 5.00
Begin VB.Form GuessForm
BorderStyle = 1 'Fixed Single
Caption = "猜數字"
ClientHeight = 2610
ClientLeft = 150
ClientTop = 435
ClientWidth = 4740
LinkTopic = "Form1"
MaxButton = 0 'False
ScaleHeight = 2610
ScaleWidth = 4740
StartUpPosition = 2 'CenterScreen
Begin VB.CommandButton Command1
Caption = "暫停"
Height = 375
Left = 1560
TabIndex = 10
Top = 1320
Width = 855
End
Begin VB.Timer Timer1
Interval = 1
Left = 3360
Top = 960
End
Begin VB.ListBox List1
Height = 1620
ItemData = "GuessForm.frx":0000
Left = 2760
List = "GuessForm.frx":0002
TabIndex = 8
Top = 600
Width = 1695
End
Begin VB.CommandButton btExit
Caption = "退出"
Height = 375
Left = 1560
TabIndex = 7
Top = 1920
Width = 855
End
Begin VB.CommandButton btOK
Caption = "確定"
Enabled = 0 'False
Height = 375
Left = 240
TabIndex = 6
Top = 1920
Width = 1095
End
Begin VB.CommandButton btRestart
Caption = "重新開始"
Height = 375
Left = 240
TabIndex = 5
Top = 1320
Width = 1095
End
Begin VB.TextBox TBNUM4
BeginProperty Font
Name = "MS Sans Serif"
Size = 9.75
Charset = 0
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 375
Left = 2040
TabIndex = 3
Top = 120
Width = 495
End
Begin VB.TextBox TBNUM3
BeginProperty Font
Name = "MS Sans Serif"
Size = 9.75
Charset = 0
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 375
Left = 1440
TabIndex = 2
Top = 120
Width = 495
End
Begin VB.TextBox TBNUM2
BeginProperty Font
Name = "MS Sans Serif"
Size = 9.75
Charset = 0
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 375
Left = 840
TabIndex = 1
Top = 120
Width = 495
End
Begin VB.TextBox TBNUM1
BeginProperty Font
Name = "MS Sans Serif"
Size = 9.75
Charset = 0
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 375
Left = 240
TabIndex = 0
Top = 120
Width = 495
End
Begin VB.Label Label2
AutoSize = -1 'True
BackColor = &H80000008&
BeginProperty Font
Name = "MS Sans Serif"
Size = 12
Charset = 0
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
ForeColor = &H0000C000&
Height = 300
Left = 3120
TabIndex = 9
Top = 120
Width = 60
End
Begin VB.Label Label1
Alignment = 2 'Center
BorderStyle = 1 'Fixed Single
BeginProperty Font
Name = "MS Sans Serif"
Size = 9.75
Charset = 0
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 375
Left = 240
TabIndex = 4
Top = 720
Width = 2295
End
Begin VB.Menu File
Caption = "文件(F)"
Begin VB.Menu OK
Caption = "確定"
End
Begin VB.Menu restar
Caption = "重新開始"
End
Begin VB.Menu div
Caption = ""
Visible = 0 'False
WindowList = -1 'True
End
Begin VB.Menu exit
Caption = "退出"
End
End
Begin VB.Menu Help
Caption = "幫助(H)"
Begin VB.Menu About
Caption = "關于猜數字"
End
End
End
Attribute VB_Name = "GuessForm"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Dim flag As Boolean
Dim initnum(1 To 4) As Integer
Dim times As Integer
Dim h0 As Integer
'ho,mo,so為初始時間
Dim m0 As Integer
Dim s0 As Integer
Dim temp1 As Integer
Dim temp2 As Integer
Dim x1 As Integer
Dim x2 As Integer
Public Sub reset()
Dim i, j As Integer
Randomize (10)
For i = 1 To 4
Do
flag = False
initnum(i) = Rnd(1) * 10
If initnum(i) = 10 Then
flag = True
End If
For j = 1 To i - 1
If initnum(i) = initnum(j) Then
flag = True
End If
Next
Loop Until flag = False
Next
TBNUM1.Text = ""
TBNUM2.Text = ""
TBNUM3.Text = ""
TBNUM4.Text = ""
times = 8
Label1.Caption = "你還有8次機會"
List1.Clear
flag = False
btOK.Enabled = True
'GuessForm.TBNUM1.SetFocus
End Sub
Public Sub subOK()
Dim InputNum(4) As Integer
Dim i As Integer, j As Integer
Dim a As Integer, b As Integer
Dim flag As Integer
Dim s As String
If TBNUM1.Text = "" Or TBNUM2.Text = "" Or TBNUM3.Text = "" Or TBNUM4.Text = "" Then
MsgBox ("必須輸入4個數字")
'判斷用戶是否已經輸入了4個數字
Else
InputNum(1) = Val(TBNUM1.Text)
InputNum(2) = Val(TBNUM2.Text)
InputNum(3) = Val(TBNUM3.Text)
InputNum(4) = Val(TBNUM4.Text)
'將游戲者的輸入存入數組,以方便通過循環語句對其進行判斷
flag = 0
For i = 1 To 3
If InputNum(i) > 9 Or InputNum(i) < 0 Then
MsgBox ("輸入數字超出范圍")
flag = 1
End If
'判斷游戲者的輸入是否在0到9之間
For j = i + 1 To 4
If InputNum(i) = InputNum(j) And i <> j Then
MsgBox ("輸入的四個數字不能重復")
flag = 1
End If
Next
'判斷游戲者輸入的四個數字是否重復
Next
If flag = 0 Then
For i = 1 To 4
For j = 1 To 4
If InputNum(i) = initnum(j) Then
If i = j Then a = a + 1 Else b = b + 1
End If
Next
Next
'判斷游戲者輸入的數字的數值及位置是否正確,如果數值及位置都正確,則a的值加1;如果只是數值正確而位置不對,則b的值加1
s = TBNUM1.Text & TBNUM2.Text & TBNUM3.Text & TBNUM4.Text & ":" & a & "A" & b & "B"
List1.AddItem (s)
'顯示中間結果
times = times - 1
Label1.Caption = "您還有" & times & "次機會"
'對游戲者的剩余次數進行遞減
If a = 4 Or times = 0 Then
If a = 4 Then
MsgBox ("恭喜過關!")
Timer1.Enabled = False
Else: MsgBox ("正確答案應為" & initnum(1) & initnum(2) & initnum(3) & initnum(4))
Timer1.Enabled = False
End If
'判斷游戲的結束和游戲者的勝負
btOK.Enabled = False
'游戲結束,將BTOK按鈕設為無效
End If
End If
End If
End Sub
Private Sub About_Click()
Dim frmabout As New fAbout
frmabout.Show
End Sub
Private Sub btExit_Click()
Unload Me
End Sub
Private Sub btOK_Click()
GuessForm.subOK
End Sub
Private Sub btRestart_Click()
Timer1.Enabled = True
Label2.Caption = ""
h0 = Val(Time$)
m0 = Minute(Time$)
s0 = Second(Time$)
GuessForm.reset
End Sub
Private Sub Command1_Click()
If Command1.Caption = "暫停" Then
Timer1.Enabled = False
Command1.Caption = "開始"
temp1 = x1
temp2 = x2
Else
If Command1.Caption = "開始" Then
Timer1.Enabled = True
h0 = Val(Time$)
m0 = Minute(Time$)
s0 = Second(Time$)
Command1.Caption = "暫停"
End If
End If
End Sub
Private Sub exit_Click()
Unload Me
End Sub
Private Sub Form_Load()
h0 = Val(Time$)
m0 = Minute(Time$)
s0 = Second(Time$)
GuessForm.reset
End Sub
Private Sub OK_Click()
GuessForm.subOK
End Sub
Private Sub restar_Click()
GuessForm.reset
End Sub
Private Sub TBNUM1_KeyPress(KeyAscii As Integer)
If Asc(KeyAscii) > 57 Or Asc(KeyAscii) < 48 Then
'判斷輸入是否為數字
MsgBox ("請輸入正確的字符")
TBNUM1.Text = ""
'顯示提示信息并清空文本框
Else
TBNUM2.SetFocus
TBNUM2.SelStart = 0
TBNUM2.SelLength = 1
'當TBNum1有輸入的時候,自動將焦點轉移到TBNum2上
End If
End Sub
Private Sub TBNUM2_KeyPress(KeyAscii As Integer)
If Asc(KeyAscii) > 57 Or Asc(KeyAscii) < 48 Then
'判斷輸入是否為數字
MsgBox ("請輸入正確的字符")
TBNUM2.Text = ""
'顯示提示信息并清空文本框
Else
TBNUM3.SetFocus
TBNUM3.SelStart = 0
TBNUM3.SelLength = 1
'當TBNum1有輸入的時候,自動將焦點轉移到TBNum2上
End If
End Sub
Private Sub TBNUM3_KeyPress(KeyAscii As Integer)
If Asc(KeyAscii) > 57 Or Asc(KeyAscii) < 48 Then
'判斷輸入是否為數字
MsgBox ("請輸入正確的字符")
TBNUM3.Text = ""
'顯示提示信息并清空文本框
Else
TBNUM4.SetFocus
TBNUM4.SelStart = 0
TBNUM4.SelLength = 1
'當TBNum1有輸入的時候,自動將焦點轉移到TBNum2上
End If
End Sub
Private Sub TBNUM4_KeyPress(KeyAscii As Integer)
If Asc(KeyAscii) > 57 Or Asc(KeyAscii) < 48 Then
'判斷輸入是否為數字
MsgBox ("請輸入正確的字符")
TBNUM4.Text = ""
'顯示提示信息并清空文本框
Else
btOK.SetFocus
'當TBNum1有輸入的時候,自動將焦點轉移到TBNum2上
End If
End Sub
Private Sub Timer1_Timer()
Dim gg As Integer
Dim h As Integer
Dim m As Integer
Dim s As Integer
'Dim x1 As Integer
'Dim x2 As Integer
h = Val(Time$)
m = Minute(Time$)
s = Second(Time$)
gg = (h - h0) * 3600 + (m - m0) * 60 + (s - s0)
x1 = temp1 + Int(gg / 60)
x2 = temp2 + (gg - (Int(gg / 60)) * 60)
Label2.Caption = Str(x1) + " 分" + Str(x2) + " 秒"
End Sub
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -