📄 set.frm
字号:
VERSION 5.00
Begin VB.Form frmSetTime
BorderStyle = 3 'Fixed Dialog
Caption = "设置定时录象"
ClientHeight = 2760
ClientLeft = 780
ClientTop = 1590
ClientWidth = 5175
LinkTopic = "Form1"
MaxButton = 0 'False
MinButton = 0 'False
ScaleHeight = 2760
ScaleWidth = 5175
ShowInTaskbar = 0 'False
Begin VB.CommandButton cmdCancel
Cancel = -1 'True
Caption = "取消"
Height = 495
Left = 3360
MaskColor = &H00000000&
TabIndex = 7
Top = 1200
Width = 1215
End
Begin VB.CommandButton cmdOK
Caption = "确定"
Default = -1 'True
Height = 495
Left = 3360
MaskColor = &H00000000&
TabIndex = 6
Top = 480
Width = 1215
End
Begin VB.TextBox txtChannel
Height = 375
Left = 1200
TabIndex = 5
Text = "3"
ToolTipText = "输入录像的频道"
Top = 1920
Width = 615
End
Begin VB.TextBox txtEnd
Height = 375
Left = 1200
TabIndex = 4
Text = "12:30 AM"
ToolTipText = "输入停止录像的时间"
Top = 1200
Width = 1215
End
Begin VB.TextBox txtStart
Height = 375
Left = 1200
TabIndex = 3
Text = "12:00 AM"
ToolTipText = "输入开始录像的时间"
Top = 480
Width = 1215
End
Begin VB.Label lblCaption
Alignment = 1 'Right Justify
Caption = "频道"
Height = 255
Index = 2
Left = 0
TabIndex = 2
Top = 2040
Width = 1095
End
Begin VB.Label lblCaption
Alignment = 1 'Right Justify
Caption = "结束时间"
Height = 255
Index = 1
Left = 0
TabIndex = 1
Top = 1320
Width = 1095
End
Begin VB.Label lblCaption
Alignment = 1 'Right Justify
Caption = "开始时间"
Height = 255
Index = 0
Left = 0
TabIndex = 0
Top = 600
Width = 1095
End
End
Attribute VB_Name = "frmSetTime"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
'**********************************************
' 目的: 本窗体用来获得用户输入的
' 设置时间和录像频道。
' 是 VCR 示例应用程序的一部分。
'**********************************************
Option Explicit
Private Sub cmdCancel_Click()
' 卸载窗体,释放引用
Unload Me
Set frmSetTime = Nothing
End Sub
Private Sub cmdOK_Click()
Dim intOK As Integer '返回值
Dim intChannel As Integer '频道号
Dim strMsg As String '信息文本
' 调用验证输入项的函数
intOK = ValidateTime(txtStart.Text, txtStart)
' 如果无效,就在这里退出
If intOK = False Then Exit Sub
' 调用验证输入项的函数
intOK = ValidateTime(txtEnd.Text, txtEnd)
' 如果无效,就在这里退出
If intOK = False Then Exit Sub
' 读取频道文本框显示的值
intChannel = Val(txtChannel)
' 如果超出范围,警告用户
If intChannel < 2 Or intChannel > 13 Then
strMsg = "频道必须在 2 和 13 之间!"
MsgBox strMsg, vbOKOnly, "无效频道"
txtChannel.SetFocus
Exit Sub
End If
' 设置 Recorder 类的属性
Recorder.StartRecording = CVar(txtStart.Text)
Recorder.StopRecording = CVar(txtEnd.Text)
Recorder.Channel = intChannel
' 卸载窗体,释放引用
Unload Me
Set frmSetTime = Nothing
End Sub
Private Sub Form_Load()
' 如果类的属性包含一个值,
' 则将其赋值给 TextBox
If Recorder.StartRecording <> Empty Then
txtStart.Text = Recorder.StartRecording
End If
If Recorder.StopRecording <> Empty Then
txtEnd.Text = Recorder.StopRecording
End If
txtChannel = Recorder.Channel
End Sub
'**********************************************
' 目的: 验证用户输入的时间字符串。
' 如果正确,将格式化字符串;
' 如果不正确,将显示一条信息。
' 输入: Time: 从文本框传递来的字符串。
' Field: 文本框控件的名称。
' 返回: True - 有效时间,
' False - 字符串不是一个有效时间。
'**********************************************
Function ValidateTime(Time As String, Field As Control) As Boolean
Dim strMsg As String ' 信息文本
' 用 IsDate 函数校验是否是有效时间
If IsDate(Time) Then
' 格式化字符串并返回 True
Field.Text = Format$(Time, "h:mm AM/PM")
ValidateTime = True
Else
' 通知用户出错
strMsg = "请输入一个有效时间!"
strMsg = strMsg & "(小时:分钟 AM/PM)"
MsgBox strMsg, vbOKOnly, "无效时间"
' 返回焦点给文本框
Field.SetFocus
' 返回 False 值
ValidateTime = False
End If
End Function
Private Sub txtChannel_GotFocus()
' 选择已经存在的文本
txtChannel.SelStart = 0
txtChannel.SelLength = Len(txtChannel.Text)
End Sub
Private Sub txtChannel_KeyPress(KeyAscii As Integer)
' 用 IsNumeric 函数确保只能输入数字
If Not IsNumeric(Chr(KeyAscii)) Then
' 不是数字,将其设置为 null
KeyAscii = 0
End If
End Sub
Private Sub txtEnd_GotFocus()
' 选择已经存在的文本
txtEnd.SelStart = 0
txtEnd.SelLength = Len(txtEnd.Text)
End Sub
Private Sub txtEnd_LostFocus()
Dim intOK As Integer ' 返回值
' 调用校验输入项的函数
intOK = ValidateTime(txtEnd.Text, txtEnd)
End Sub
Private Sub txtStart_GotFocus()
' 选择已经存在的文本
txtStart.SelStart = 0
txtStart.SelLength = Len(txtStart.Text)
End Sub
Private Sub txtStart_LostFocus()
Dim intOK As Integer '返回值
' 调用校验输入项的函数
intOK = ValidateTime(txtStart.Text, txtStart)
End Sub
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -