frmmain.frm
来自「《Visual Basic 6.0趣味程序导学》光盘」· FRM 代码 · 共 399 行
FRM
399 行
VERSION 5.00
Begin VB.Form frmMain
BackColor = &H80000005&
BorderStyle = 1 'Fixed Single
Caption = """幸运52""模拟小游戏"
ClientHeight = 6165
ClientLeft = 45
ClientTop = 330
ClientWidth = 8055
BeginProperty Font
Name = "宋体"
Size = 9.75
Charset = 0
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
LinkTopic = "Form1"
MaxButton = 0 'False
ScaleHeight = 411
ScaleMode = 3 'Pixel
ScaleWidth = 537
StartUpPosition = 2 '屏幕中心
Begin VB.CommandButton cmdExit
Caption = "退出(&X)"
Height = 495
Left = 6180
TabIndex = 3
Top = 5160
Width = 1350
End
Begin VB.CommandButton cmdOK
Caption = "确定(&Y)"
Enabled = 0 'False
Height = 495
Left = 4740
TabIndex = 2
Top = 5160
Width = 1350
End
Begin VB.CommandButton cmdStart
Caption = "开始游戏(&S)"
Height = 495
Left = 3300
TabIndex = 1
Top = 5160
Width = 1350
End
Begin VB.TextBox txtPrice
Alignment = 2 'Center
BeginProperty Font
Name = "宋体"
Size = 12
Charset = 0
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 450
Left = 3840
TabIndex = 4
Top = 3360
Width = 2295
End
Begin VB.Image imgCommodity
Height = 2895
Index = 9
Left = 300
Picture = "frmMain.frx":0000
Stretch = -1 'True
Top = 3000
Visible = 0 'False
Width = 2550
End
Begin VB.Image imgCommodity
Height = 2895
Index = 8
Left = 300
Picture = "frmMain.frx":1A73
Stretch = -1 'True
Top = 3000
Visible = 0 'False
Width = 2550
End
Begin VB.Image imgCommodity
Height = 2895
Index = 7
Left = 300
Picture = "frmMain.frx":3284
Stretch = -1 'True
Top = 3000
Visible = 0 'False
Width = 2550
End
Begin VB.Image imgCommodity
Height = 2895
Index = 6
Left = 300
Picture = "frmMain.frx":47A8
Stretch = -1 'True
Top = 3000
Visible = 0 'False
Width = 2550
End
Begin VB.Image imgCommodity
Height = 2895
Index = 5
Left = 300
Picture = "frmMain.frx":7903
Stretch = -1 'True
Top = 3000
Visible = 0 'False
Width = 2550
End
Begin VB.Image imgCommodity
Height = 2895
Index = 4
Left = 300
Picture = "frmMain.frx":BB34
Stretch = -1 'True
Top = 3000
Visible = 0 'False
Width = 2550
End
Begin VB.Image imgCommodity
Height = 2895
Index = 3
Left = 300
Picture = "frmMain.frx":115D0
Stretch = -1 'True
Top = 3000
Visible = 0 'False
Width = 2550
End
Begin VB.Image imgCommodity
Height = 2895
Index = 2
Left = 300
Picture = "frmMain.frx":164FA
Stretch = -1 'True
Top = 3000
Visible = 0 'False
Width = 2550
End
Begin VB.Image imgCommodity
Height = 2895
Index = 1
Left = 300
Picture = "frmMain.frx":17761
Stretch = -1 'True
Top = 3000
Visible = 0 'False
Width = 2550
End
Begin VB.Image imgCommodity
Height = 2895
Index = 0
Left = 300
Picture = "frmMain.frx":19636
Stretch = -1 'True
Top = 3000
Visible = 0 'False
Width = 2550
End
Begin VB.Label Label7
BackColor = &H80000005&
Caption = "游戏规则:"
BeginProperty Font
Name = "宋体"
Size = 12
Charset = 0
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 300
Left = 360
TabIndex = 10
Top = 120
Width = 1335
End
Begin VB.Label Label6
BackColor = &H80000005&
Caption = "请单击""确定""按钮对您的估计值进行确定:"
BeginProperty Font
Name = "宋体"
Size = 12
Charset = 0
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 300
Left = 3120
TabIndex = 9
Top = 4320
Width = 4665
End
Begin VB.Label Label5
BackColor = &H80000005&
Caption = "请在输入框中输入您对商品价格的估计:"
BeginProperty Font
Name = "宋体"
Size = 12
Charset = 0
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 300
Left = 3120
TabIndex = 8
Top = 2520
Width = 4500
End
Begin VB.Label lblCommodityName
BackColor = &H80000005&
Caption = "产品名称(未选定)"
BeginProperty Font
Name = "宋体"
Size = 12
Charset = 0
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
ForeColor = &H000000FF&
Height = 300
Left = 435
TabIndex = 7
Top = 2460
Width = 2340
End
Begin VB.Label Label3
AutoSize = -1 'True
BackColor = &H80000005&
Caption = $"frmMain.frx":1B9F5
BeginProperty Font
Name = "宋体"
Size = 12
Charset = 0
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 720
Left = 300
TabIndex = 6
Top = 1560
Width = 7200
WordWrap = -1 'True
End
Begin VB.Label Label2
AutoSize = -1 'True
BackColor = &H80000005&
Caption = "2.请迅速在输入框中输入您估计的商品价格,然后单击""确定""按钮。"
BeginProperty Font
Name = "宋体"
Size = 12
Charset = 0
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 240
Left = 300
TabIndex = 5
Top = 1080
Width = 7500
WordWrap = -1 'True
End
Begin VB.Label Label1
BackColor = &H80000005&
Caption = "1.单击""开始游戏""按钮,游戏开始,系统将给出商品信息。"
BeginProperty Font
Name = "宋体"
Size = 12
Charset = 0
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 300
Left = 300
TabIndex = 0
Top = 600
Width = 7500
WordWrap = -1 'True
End
End
Attribute VB_Name = "frmMain"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit
Private ma_lngCommodityPrice(0 To 9) As Long
Private ma_strCommodityName(0 To 9) As String
Private m_intCurrentCommodity As Integer
Private Sub cmdExit_Click()
'单击退出按钮,卸载主窗体,退出程序
Unload Me
End Sub
Private Sub cmdOK_Click()
Dim lngPriceTemp As Long
'如果发生输入错误则跳到错误处理段
On Error GoTo InputError
lngPriceTemp = CLng(txtPrice.Text)
If lngPriceTemp < 0 Then
MsgBox "您难道想我倒贴钱吗?", vbOKOnly, "输入错误"
ElseIf (lngPriceTemp > ma_lngCommodityPrice(m_intCurrentCommodity)) Then
MsgBox "您想用 " & txtPrice.Text & " 块钱买这个破东西?!高了高了!!", vbOKOnly, "猜错了"
ElseIf (lngPriceTemp < ma_lngCommodityPrice(m_intCurrentCommodity)) Then
MsgBox "您想用 " & txtPrice.Text & " 块这么少的钱买这个好东西?!低了低了!!", vbOKOnly, "猜错了"
Else
MsgBox "恭喜恭喜!!", vbOKOnly, "猜对了"
cmdOK.Enabled = False
End If
'清空文本框,并使其获得焦点
txtPrice.SetFocus
txtPrice.Text = ""
Exit Sub
InputError:
MsgBox "输入有误,只能输入正整数!", vbOKOnly, "输入错误"
txtPrice.Text = ""
txtPrice.SetFocus
End Sub
Private Sub cmdStart_Click()
'游戏开始,设置确定按钮为可用,使文本框获得焦点
cmdOK.Enabled = True
txtPrice.SetFocus
txtPrice.Text = ""
'初始化随机数种子,得到一个0-9内的随机整数
Randomize
m_intCurrentCommodity = Int(10 * Rnd)
lblCommodityName.Caption = ma_strCommodityName(m_intCurrentCommodity)
'先把所有图片控件都设为不可见,再把需要显示的一个设为可见
Dim intTemp As Integer
For intTemp = 0 To 9
imgCommodity(intTemp).Visible = False
Next intTemp
imgCommodity(m_intCurrentCommodity).Visible = True
End Sub
Private Sub Form_Load()
'初始化物品名字和价格
ma_strCommodityName(0) = "康佳29寸纯平彩电"
ma_strCommodityName(1) = "松下掌上电脑"
ma_strCommodityName(2) = "IBM笔记本电脑"
ma_strCommodityName(3) = "捷视可视电话机2000T"
ma_strCommodityName(4) = "索尼随身听EX2000 "
ma_strCommodityName(5) = "索尼数码相机DSC-P1"
ma_strCommodityName(6) = "松下剃须刀ES365A"
ma_strCommodityName(7) = "日本ESP电吉它"
ma_strCommodityName(8) = "Nokiya 8210手机"
ma_strCommodityName(9) = "奔驰500"
ma_lngCommodityPrice(0) = 4390
ma_lngCommodityPrice(1) = 5230
ma_lngCommodityPrice(2) = 2079
ma_lngCommodityPrice(3) = 5380
ma_lngCommodityPrice(4) = 1224
ma_lngCommodityPrice(5) = 7140
ma_lngCommodityPrice(6) = 273
ma_lngCommodityPrice(7) = 5230
ma_lngCommodityPrice(8) = 2810
ma_lngCommodityPrice(9) = 1200000
End Sub
Private Sub Label3_Click()
End Sub
Private Sub txtPrice_KeyPress(KeyAscii As Integer)
'如果文本框获得焦点时
'按下ESC键清空文本框,按下回车键结束输入,相当于按下确定按钮
If KeyAscii = vbKeyEscape Then
txtPrice.Text = ""
ElseIf KeyAscii = vbKeyReturn Then
cmdOK_Click
End If
End Sub
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?