📄 9选3.frm
字号:
VERSION 5.00
Begin VB.Form Form1
Caption = "9选3"
ClientHeight = 4215
ClientLeft = 60
ClientTop = 450
ClientWidth = 3225
LinkTopic = "Form1"
ScaleHeight = 4215
ScaleWidth = 3225
StartUpPosition = 3 '窗口缺省
Begin VB.TextBox Text1
BackColor = &H00FF0000&
Height = 375
Left = 240
Locked = -1 'True
TabIndex = 14
Top = 3480
Width = 975
End
Begin VB.CommandButton Command2
Caption = "重新开始"
Height = 375
Left = 1560
TabIndex = 9
Top = 3480
Width = 1095
End
Begin VB.CommandButton Command1
Caption = "9"
Height = 375
Index = 9
Left = 2040
TabIndex = 8
Top = 240
Width = 495
End
Begin VB.CommandButton Command1
Caption = "8"
Height = 375
Index = 8
Left = 1320
TabIndex = 7
Top = 240
Width = 495
End
Begin VB.CommandButton Command1
Caption = "7"
Height = 375
Index = 7
Left = 600
TabIndex = 6
Top = 240
Width = 495
End
Begin VB.CommandButton Command1
Caption = "6"
Height = 375
Index = 6
Left = 600
TabIndex = 5
Top = 840
Width = 495
End
Begin VB.CommandButton Command1
Caption = "5"
Height = 375
Index = 5
Left = 1320
TabIndex = 4
Top = 840
Width = 495
End
Begin VB.CommandButton Command1
Caption = "4"
Height = 375
Index = 4
Left = 2040
TabIndex = 3
Top = 840
Width = 495
End
Begin VB.CommandButton Command1
Caption = "3"
Height = 375
Index = 3
Left = 600
TabIndex = 2
Top = 1440
Width = 495
End
Begin VB.CommandButton Command1
Caption = "2"
Height = 375
Index = 2
Left = 1320
TabIndex = 1
Top = 1440
Width = 495
End
Begin VB.CommandButton Command1
Caption = "1"
Height = 375
Index = 1
Left = 2040
TabIndex = 0
Top = 1440
Width = 495
End
Begin VB.Label Label2
Caption = "成 绩"
Height = 255
Left = 480
TabIndex = 13
Top = 3120
Width = 615
End
Begin VB.Label Label1
Height = 495
Index = 2
Left = 2160
TabIndex = 12
Top = 2280
Width = 495
End
Begin VB.Label Label1
Height = 495
Index = 1
Left = 1200
TabIndex = 11
Top = 2280
Width = 615
End
Begin VB.Label Label1
Height = 495
Index = 0
Left = 360
TabIndex = 10
Top = 2280
Width = 615
End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Dim d(0 To 2) As Integer '存储电脑随机产生的三个1~9之间整数
Dim count1, count2 As Integer 'count1统计用户猜了几次,count2统计用户猜对了几次
Private Sub Command1_Click(Index As Integer)
Command1(Index).Enabled = False '将当前数字按钮置为不可用
Label1(count1).Caption = Str(Index) '获得用户当前按下的键
count1 = count1 + 1
For i = 0 To 2
If d(i) = Index Then '猜对了一个数
count2 = count2 + 1
Label1(count1 - 1).BackColor = vbYellow '将背景色设置为黄色
End If
Next i
If count1 = 3 Then '已经猜了三个数字
For i = 1 To 9
Command1(i).Enabled = False '将所有数字置为不可用
Next i
Text1.Text = Str(count2) '输出猜对的次数
End If
End Sub
Private Sub Command2_Click()
Call init
End Sub
Private Sub Form_Load()
Call init
End Sub
Sub setv() '产生1~9之间三个不同的数字存入数组d
Dim same As Boolean '变量same用于判断是否产生过
k = 0
Do While k < 3
n = Fix(Timer() * Rnd() * 100) Mod 9 + 1 '随机产生一个数
same = False
For i = 0 To k - 1 '判断产生的随机数是否产生过了
If d(i) = n Then same = True
Next i
If same = False Then
d(k) = n '没有产生过,存入数组
k = k + 1
End If
Loop
End Sub
Sub init()
For i = 1 To 9
Command1(i).Enabled = True '将所有数字按钮置为可用
Next i
count1 = 0: count2 = 0 '将计数器清0
For i = 0 To 2
Label1(i).BackColor = &H8000000F '将背景置为窗体颜色
Label1(i).Caption = ""
Next i
Text1.Text = ""
Call setv
End Sub
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -