请教一个VB倒计时的程序代码实现功能

来源:百度知道 编辑:UC知道 时间:2024/06/16 04:05:50
最近闲来无事,想用VB编个倒计时的程序,就像奥运会倒计时一样,显示“距离北京奥运还有XX天XX小时XX分XX秒”,计时功能通过网上资料参考,已经实现,现在遇上个问题,北京奥运会是2008年8月8日晚上20点,我现在想实现一个功能,放置一个文本框,可以用来给我输入一个日期和时间,然后将文本框中的值与当前计算,得出剩余的时间,不知道这个功能怎么实现,200分请教,谢谢。

实现倒计时计算的代码如下:
(窗口放置一个Timer、四个Label控件)

Dim b, c, d, e As Long
Dim OK

Private Sub Form_Load()
Timer1.Interval = 1000
Dim a As Long
OK = "2008-8-8 20:00:00"
a = DateDiff("s", Now(), CDate(OK))
b = Int(a / 24 / 3600)
c = Int((a - b * 24 * 3600) / 3600)
d = Int((a - b * 24 * 3600 - c * 3600) / 60)
e = a - b * 24 * 3600 - c * 3600 - d * 60
Timer1.Enabled = True
Label1.Caption = b
Label2.Caption = c
Label3.Caption = d
Label4.Caption = e
End Sub

Private Sub Timer1_Timer()
If e = 0 Then
e = 59
If d = 0 Then
d = 59
If c = 0 Then
c = 23
If b = 0 Then
Timer1.Enabled = False

根据你给出的代码,帮你实现了托盘和气泡的显示问题。
输入时间没办法实现,因为没有数据库支持输入记录。

代码:

1、新建一个以SysTray命名的模块,里面加入代码:
Option Explicit
Declare Function Shell_NotifyIcon Lib "shell32.dll" Alias _
"Shell_NotifyIconA" (ByVal dwMessage As Long, _
lpData As NOTIFYICONDATA) As Long

Public Type NOTIFYICONDATA
cbSize As Long
hwnd As Long
uId As Long
uFlags As Long
uCallBackMessage As Long
hIcon As Long
szTip As String * 128
dwState As Long
dwStateMask As Long
szInfo As String * 256
uTimeoutOrVersion As Long
szInfoTitle As String * 64
dwInfoFlags As Long
End Type

Public Const NOTIFYICON_VERSION = 3
Public Const NOTIFYICON_OLDVERSION = 0

Public Const NIM_ADD = &H0
Public Const NIM_MODIFY = &H1
Public Const NIM_DELETE = &H2

Public Const NIM_SETFOCUS = &H3
Public Const NIM_SETVERSION = &H4

Public Const NIF_MESSAGE = &H1