|
网站首页
|
JAVA文章
|
AppServers
|
Web开发
|
应用开发
|
资源下载
|
论坛
想学好编程,学好外语很重要 [enadd 2006年12月25日]
设为首页
加入收藏
联系站长
您现在的位置:
编程笔记网
>>
应用开发
>>
vb
>>
系统
>> 文章正文
用VB设计一个定时闹钟程序
【字体:
小
大
】
用VB设计一个定时闹钟程序
作者:未知 文章来源:- 点击数: 更新时间:2006-8-9
用VB设计一个定时闹钟程序
使用win98的人一定知道其中有一个“计划任务"的应用程序,它能够到指定时间便开始工作。不要认为它很神秘,其实用VB来设计这样一个程序是非常容易的事,以下是一个简单的VB闹钟程序,可供各位使用VB的朋友参考,如有何不适之处,请多指点!
首先在form1上建立三个命令按钮,分别为command1(打开预启动的文件);command2(设定时间的按钮);第三个command3(即可启动)按钮可有可无;一个label1用来显示你预打开的文件名的路径;一个lbltime用来显示现在的时间;还有一个common dialog,它在工程菜单的部件中,你可把它加到工具箱中再开始使用;关于对话框你不必自己建,只要从应用程序向导中添加即可;一个timer,它的interval=500。
其次在form1的属性中设置为:startupposition=2-centerscreen和maxbutton=false;label1的属性中设置为:alignment=2-center。
外观大致是如图所示:
下面我们开始编程:
Option Explicit
Dim AlarmTime
'申明变量
---------
Private Sub Command1_Click()
Call dialog
'调用dialog子程序
End Sub
--------
Private Sub Command2_Click()
AlarmTime = InputBox(“请输入你想设定的时间,例如(19:12:00)", “小闹钟")
If AlarmTime = “" Then Exit Sub
If Not IsDate(AlarmTime) Then
MsgBox “你所输入的不是时间格式,请重试!", ,“Wrong"
Else
AlarmTime = CDate(AlarmTime)
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_Load()
Command3.Enabled = 0
AlarmTime = “"
'初始化时command3为不可用的
End Sub
---------------
Private Sub Form_Resize()
If WindowState = 1 Then
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
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
最后在about对话框中要提的是:在form_load中app.title表示你的应用程序的名字;app.major、minor、revision是关于应用程序的版本信息;lblDescription.Caption 用于对本程序的一些说明描述之类的话;lblDisclaimer.Caption用于版权信息或警告等。
[1]
[2]
下一页
文章录入:enadd 责任编辑:enadd
上一篇文章:
自动记录应用软件工作时间
下一篇文章:
VB设计动画时钟
【
发表评论
】【
加入收藏
】【
告诉好友
】【
打印此文
】【
关闭窗口
】
最新热点
最新推荐
相关文章
用VB编写DirectX7.0游戏(下…
用VB编写DirectX7.0游戏(上…
使用OLE DB和ADO调用返回记录…
使用VB调用Oracle程序包内的…
VB中用ADO对象动态创建数据库…
fffff
如何用MSComm Control传Bina…
MultiLink的WinSock Server程…
用VB制作浏览器
用VB编写网络寻呼机
网友评论:
(只显示最新10条。评论内容只代表网友观点,与本站立场无关!)
|
设为首页
|
加入收藏
|
联系站长
|
友情链接
|
版权申明
|
管理登录
|
Copyright ©2000 - 2005
Enadd
.com
备案序号:辽ICP备06005595号
QQ:1656107
站长:
enadd