
正文
vb.net编程闹钟 编程闹钟视频
提示:扫一扫查出行【扫一扫了解最新限行尾号】
复制提示
怎样用vb编写一个闹钟
修改完毕,并添加了注释
-------------------------------------------
Option Explicit
Dim AlarmTime '申明变量(这个样子定义变量行吗vb.net编程闹钟?是什么类型?)
'将AlarmTime申明为变体型(Variant)
Private Sub Command1_Click()
Call dialog '调用dialog子程序
End Sub
Private Sub Form_Load()
Command3.Enabled = False '初始化时command3为不可用vb.net编程闹钟的
AlarmTime = "" '(这样的话不就是当成字符串的形式了么?
'此时AlarmTime为字符串型(String)
End Sub
Private Sub Command2_Click()
'AlarmTime = InputBox("请输入vb.net编程闹钟你想设定的时间,例如(19:12:00)", "小闹钟").
AlarmTime = InputBox("请输入vb.net编程闹钟你想设定的时间,例如(19:12:00)", "小闹钟")
'此时AlarmTime为字符串型(String)
'If AlarmTime = "Then Exit Sub"
If AlarmTime = "" Then Exit Sub
If Not IsDate(AlarmTime) Then
MsgBox "vb.net编程闹钟你所输入的不是时间格式,请重试!", , "Wrong"
Else
AlarmTime = CDate(AlarmTime)
'此时AlarmTime为日期型(Date)
End If
'判断输入的是否可转换成time格式
'isdate函数是判断输入的是否可转换成date格式
End Sub
Private Sub Command3_Click()
Call deng
'调用deng子程序
End Sub
Private Sub Form_Click()
frmabout.Show
'显示关于对话框
End Sub
Private Sub Form_Resize()
If WindowState = 1 Then
Call mintime
Else
Caption = "小闹钟"
End If
'如果窗口被最小化,则调用mintime程序
End Sub
Private Sub mintime()
Caption = Format(Time, "long Time")
'使用长时间格式来显示时间
End Sub
Private Sub Timer1_Timer()
If lbltime.Caption CStr(Time) Then
lbltime.Caption = Time
End If
'显示时间每秒钟的变化
If Time = AlarmTime Then
Call deng
End If
'判断如果现在的时间超过了设定的时间,则调用deng子程序
If WindowState = 1 Then
If Minute(CDate(Caption)) Minute(Time) Then
mintime
End If
End If
'最小化时显示时间每分钟的变化
End Sub
Sub dialog()
CommonDialog1.Flags = cdlCFBoth
CommonDialog1.ShowOpen
Label1.Caption = CommonDialog1.FileName
'If Label1 " Then
If Label1 "" Then
Command3.Enabled = -1
Else
Exit Sub
End If
'把打开的文件名给于label1
'如果label1不为空时,则command3即可用
End Sub
Sub deng()
Dim ss
ss = Shell(Label1.Caption, 1)
End
'启动指定的文件,并且结束小闹钟程序
End Sub
相关问答
Q1: 利用vb.net实现小闹钟功能
Private Declare Function mciSendStringA Lib "winmm.dll" _
(ByVal lpstrCommand As String, ByVal lpstrReturnString As String, _
ByVal uReturnLength As Integer, ByVal hwndCallback As Integer) As Integer
Function PlayMidiFile(ByVal MusicFile As String) As Boolean
If System.IO.File.Exists(MusicFile) Then
mciSendStringA("stop music", "", 0, 0)
mciSendStringA("close music", "", 0, 0)
mciSendStringA("open " MusicFile " alias music", "", 0, 0)
PlayMidiFile = mciSendStringA("play music", "", 0, 0) = 0
End If
End Function
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
If TextBox1.Text = TimeOfDay Then
'具体提醒的东西,如你说的播放音乐
PlayMidiFile("自己添加路径")
End If
'时间格式要是这样的16:00:00
'timer的interval要设成1
'你还可以自己细化
End Sub
Q2: 跪求用vb.net做一个小闹钟!!
'加个定时器,textbox ,button,label Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
Label1.Text = Now
If FF = Now And FF "2001-1-1" And Timer1.Tag = "" Then
Timer1.Tag = "1"
MsgBox("ff")
End If
End Sub Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
FF = TextBox1.Text
Timer1.Tag = ""
End Sub Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
FF = "2001-1-1"
End Sub'声音加个 AxMMControl控件 AxMMControl1.DeviceType = "waveaudio" ''''''''定义播放*.wav格式 AxMMControl1.FileName = "c:\1.wav" ''''''''载入文件, AxMMControl1.Command = "open" ''''''''打开载入的文件
AxMMControl1.From = 0 '从头开始
AxMMControl1.Command = "play"'保存时间,只要设定时把时间保存到文本文件就行,load 事件中读取,并对比是不是超时,.
Q3: VB 闹钟代码
那是因为vb.net编程闹钟你自己没添加对应的控件导致的 你将下面内容 复制到 记事本中 另存为1.frm文件 打开即可 还有你得保证你同目录下 有Bilp.wav 这个音频文件
VERSION 5.00
Begin VB.Form Form1
Caption = "Form1"
ClientHeight = 1665
ClientLeft = 60
ClientTop = 450
ClientWidth = 1725
LinkTopic = "Form1"
ScaleHeight = 1665
ScaleWidth = 1725
StartUpPosition = 3 '窗口缺省
Begin VB.CommandButton Command2
Caption = "退出"
Height = 375
Left = 960
TabIndex = 3
Top = 840
Width = 615
End
Begin VB.TextBox Text2
Height = 270
Left = 720
TabIndex = 2
Top = 480
Width = 855
End
Begin VB.CommandButton Command1
Caption = "开始"
Height = 375
Left = 120
TabIndex = 1
Top = 840
Width = 615
End
Begin VB.TextBox Text1
Height = 270
Left = 720
TabIndex = 0
Top = 120
Width = 855
End
Begin VB.Timer Timer1
Left = 360
Top = 1200
End
Begin VB.Label Label2
AutoSize = -1 'True
Caption = "分钟:"
Height = 180
Left = 120
TabIndex = 5
Top = 480
Width = 540
End
Begin VB.Label Label1
AutoSize = -1 'True
Caption = "小时:"
Height = 180
Left = 120
TabIndex = 4
Top = 120
Width = 540
End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Private Declare Function PlaySound Lib "winmm.dll" Alias "PlaySoundA" _
(ByVal IpszName As String, ByVal hModule As Long, ByVal dwflags As Long) As Long
Private Sub Form_Load()
Timer1.Interval = 1000
Timer1.Enabled = False '停止运行定时器
End Sub
'单击“开始”按纽vb.net编程闹钟,输入定时时间,并启动定时器
Private Sub Command1_Click()
Command1.Enabled = False
If Val(Text1) 1 Or Val(Text1) 24 Then
MsgBox "小时数输入错误!", vbExclamation, "提示信息"
Text1 = ""
Text1.SetFocus
Command1.Enabled = True
End If
If Val(Text2) 1 Or Val(Text2) 60 Then
MsgBox "分钟数输入错误!", vbExclamation, "提示信息"
Text2 = ""
Text2.SetFocus
Command1.Enabled = True
End If
Timer1.Enabled = True
End Sub
'单击“结束”按纽,退出程序
Private Sub Command2_Click()
End
End Sub
'当系统时间到达定时时间时,定时播放提示音
Private Sub Timer1_Timer()
If Val(Text1.Text) = Hour(Time) Then
If Val(Text2.Text) = Minute(Time) Then
Call PlaySound(App.Path + "\Bilp.wav", 0, H0)
End If
End If
End Sub
vb.net编程闹钟的介绍就聊到这里吧,感谢你花时间阅读本站内容,更多关于编程闹钟视频、vb.net编程闹钟的信息别忘了在本站进行查找喔。




![[Canon.EOS.60D完全摄影手册].陈磊.全彩扫描版 [Canon.EOS.60D完全摄影手册].陈磊.全彩扫描版](https://www.04ip.com/template/qe/style/noimg/16.jpg)
![【电子书】[历史军事] 《半小时漫画中国史2》[陈磊(笔名:二混子)][mobi] 【电子书】[历史军事] 《半小时漫画中国史2》[陈磊(笔名:二混子)][mobi]](https://www.04ip.com/template/qe/style/noimg/9.jpg)
