求VB 倒数时间代码,距离XX还有多少天的那种。 vb中 距离某一天还有多少天 表达式

VB\u3002\u8ba1\u7b97\u67d0\u4e2a\u65e5\u671f\u8ddd\u79bb\u73b0\u5728\u8fd8\u6709\u591a\u5c11\u5929\u7684\u5012\u8ba1\u65f6\u5668\u3002

\u2018\u53ef\u4ee5\u662f\u5929\uff0c\u6211\u8fd9\u91cc\u8bbe\u7f6e\u4e86s
Private Sub Command1_Click()
If Command1.Caption = "\u5f00\u59cb\u5012\u8ba1\u65f6" Then
If Not IsDate(Text1) Then Exit Sub\u2019\u65e0\u6548\u7684\u65e5\u671f
Command1.Caption = "\u505c\u6b62\u5012\u8ba1\u65f6"
Timer1.Interval = 500
Text1.Enabled = False
Else
Command1.Caption = "\u5f00\u59cb\u5012\u8ba1\u65f6"
Timer1.Interval = 0
Text1.Enabled = True
End If
End Sub
Private Sub Form_Load()
Text1 = #12/21/2012#
Command1.Caption = "\u5f00\u59cb\u5012\u8ba1\u65f6"
End Sub
Private Sub Timer1_Timer()
Me.Caption = "\u73b0\u5728\u65f6\u95f4:" & Now() & Space(4) & "\u5730\u7403\u672b\u65e5:" & CDate(Text1) & Space(4) & "\u8fd8\u80fd\u6d3b(s):" & DateDiff("s", Now, CDate(Text1))
End Sub

vb6\u4e2d\u7528\u51fd\u6570
DateDiff(interval, date1, date2)
\u53ef\u4ee5\u8ba1\u7b97date1\u4e0edate2\u76f8\u5dee\u7684\u95f4\u9694\u6570\u76ee\u3002
\u8981\u60f3\u8ba1\u7b97date1\u4e0edate2\u4e4b\u95f4\u76f8\u5dee\u7684\u5929\u6570\uff0c\u53d8\u91cf interval \u7528 d \u5c31\u53ef\u4ee5\u4e86.
\u5982: DateDiff("d",'2017/05/01",date) \u8ba1\u7b97\u51fa2017\u5e7405\u670801\u65e5\u4e0e\u4eca\u5929\u4e4b\u95f4\u76f8\u5dee\u7684\u5929\u6570.

放置两个command(一个叫做cmdDel,另一个叫做cmdAdd)和一个Timer(叫做tmrDJS)
窗体的StartUpPosition属性设为2 - CenterScreen

并添加以下代码:

Private Sub cmdAdd_Click()
Dim sName As String, AllNum As Integer, TerminateDate As Date
sName = InputBox("倒计时的名字?")
TerminateDate = InputBox("截止时间?例如2009-10-20 3:23:19")
AllNum = GetSetting("倒计时", "倒计时列表", "倒计时总数", "0")
AllNum = AllNum + 1
SaveSetting "倒计时", "倒计时列表", "倒计时总数", AllNum
SaveSetting "倒计时", "倒计时列表", "时间" & Trim(Str(AllNum)), TerminateDate
SaveSetting "倒计时", "倒计时列表", "名字" & Trim(Str(AllNum)), sName
MsgBox "添加成功!", vbInformation
End Sub

Private Sub cmdDel_Click()
Dim Qx As Integer
Qx = InputBox("列表中的几个?")
Dim sDate As String, sName As String, AllNum As Integer, Qu As Integer
AllNum = GetSetting("倒计时", "倒计时列表", "倒计时总数", "0")
For i = 1 To AllNum
sDate = GetSetting("倒计时", "倒计时列表", "时间" & Trim(Str(i)), "0")
sName = GetSetting("倒计时", "倒计时列表", "名字" & Trim(Str(i)), "0")
If sDate <> "0" Then
Qu = Qu + 1
If Qu = Qx Then
If MsgBox("是要删除倒计时 " & sName & " 吗?", vbYesNo + vbQuestion) = vbYes Then
SaveSetting "倒计时", "倒计时列表", "时间" & Trim(Str(i)), "0"
End If
Exit For
End If
End If
Next i
End Sub

Private Sub Form_Load()
Height = 3570
Width = 5550
Caption = "倒计时"
tmrDJS.Interval = 500
cmdAdd.Left = 4200
cmdAdd.Top = 2520
cmdAdd.Height = 255
cmdAdd.Width = 1215
cmdAdd.Caption = "添加倒计时"
cmdDel.Left = 4200
cmdDel.Top = 2760
cmdDel.Height = 255
cmdDel.Width = 1215
cmdDel.Caption = "删除倒计时"
End Sub

Private Sub tmrDJS_Timer()
Cls
Dim DJS As Date, sDate As String, sName As String, AllNum As Integer, Printed As Boolean
Dim Kd As Double
AllNum = GetSetting("倒计时", "倒计时列表", "倒计时总数", "0")
For i = 1 To AllNum
sDate = GetSetting("倒计时", "倒计时列表", "时间" & Trim(Str(i)), "0")
sName = GetSetting("倒计时", "倒计时列表", "名字" & Trim(Str(i)), "0")
If sDate <> "0" Then
DJS = sDate
If DJS - Now <= 0 Then
Print sName; " 已经到了!"
Else
Kd = DJS - Now
Print "距离 "; sName; " 还有 ";
Print Int(Kd); " 天 ";
Kd = Kd - Int(Kd)
Print Int(Kd * 24); " 小时";
Kd = Kd - Int(Kd * 24) / 24
Print Int(Kd * 24 * 60); " 分钟";
Kd = Kd - Int(Kd * 24 * 60) / 24 / 60
Print Int(Kd * 24 * 60 * 60 + 0.5); " 秒"
End If
Printed = True
End If
Next i
If Not Printed Then Print "列表为空!"
End Sub

然后运行即可~

我记得写过给你的,没给分不算,换个马甲还又发这个问题,还0分!无语!
http://zhidao.baidu.com/question/114913658.html

给你两个办法!
一是调用flash,
1、在本机建立一个html文件,代码如下:
<embed
src="http://blog-apart.com/COUNT/count2.swf"
quality="high"
width="150"
height="180"
FlashVars="yy=2007&mm=2&dd=14&hh=0&titler=情人节&urler=http://blog.sina.com.cn/m/lz_peach">
2、建立VB程序,添加wenbrowser控件,代码如下:
Option
Explicit
Private
Declare
Function
SetWindowPos&
Lib
"user32"
(ByVal
hwnd
As
Long,
ByVal
hWndInsertAfter
As
Long,
ByVal
x
As
Long,
ByVal
y
As
Long,
ByVal
cx
As
Long,
ByVal
cy
As
Long,
ByVal
wFlags
As
Long)
Private
Sub
Form_Activate()
WebBrowser1.Navigate
"HTML文件地址\123.html"
Dim
myval
myval
=
SetWindowPos(Form1.hwnd,
-1,
0,
0,
0,
0,
3)
End
Sub
Private
Sub
Form_Load()
With
Form1
.BorderStyle
=
None
.Height
=
2655
.Width
=
2175
.Left
=
Screen.Width
-
Me.Width
.Top
=
Screen.Height
-
Me.Height
End
With
With
WebBrowser1
.Width
=
2895
.Height
=
3300
.Top
=
-240
.Left
=
-240
End
With
End
Sub
二,自己写计时器
待续。。。
Private
Declare
Function
SetWindowPos&
Lib
"user32"
(ByVal
hwnd
As
Long,
ByVal
hWndInsertAfter
As
Long,
ByVal
x
As
Long,
ByVal
y
As
Long,
ByVal
cx
As
Long,
ByVal
cy
As
Long,
ByVal
wFlags
As
Long)
Private
Declare
Sub
GetLocalTime
Lib
"kernel32"
(lpSystemTime
As
SYSTEMTIME)
Private
Type
SYSTEMTIME
wYear
As
Integer
wMonth
As
Integer
wDayOfWeek
As
Integer
wDay
As
Integer
wHour
As
Integer
wMinute
As
Integer
wSecond
As
Integer
wMilliseconds
As
Integer
End
Type
Dim
aa
As
Date
Private
Sub
Form_Activate()
Dim
myval
myval
=
SetWindowPos(Form1.hwnd,
-1,
0,
0,
0,
0,
3)
End
Sub
Private
Sub
Form_Load()
aa
=
"2009-9-3"
With
Form1
.BackColor
=
&H80000007
.BorderStyle
=
None
.Left
=
Screen.Width
-
Me.Width
.Top
=
Screen.Height
-
Me.Height
End
With
With
Label1
.Alignment
=
2
.BackStyle
=
0
.FontSize
=
24
.ForeColor
=
&H8000000E
End
With
With
Label2
.Alignment
=
2
.BackStyle
=
0
.FontSize
=
12
.ForeColor
=
&H8000000E
End
With
With
Label3
.Alignment
=
2
.BackStyle
=
0
.FontSize
=
12
.ForeColor
=
&HFF&
End
With
Dim
sys
As
SYSTEMTIME
GetLocalTime
sys
Timer1.Interval
=
100
Timer1.Enabled
=
True
Label1.Caption
=
Format(Date,
"yyyy年mm月dd日")
Label2.Caption
=
Time
&
":"
&
Int(CLng(sys.wMilliseconds)
/
100)
End
Sub
Private
Sub
Timer1_Timer()
Dim
sys
As
SYSTEMTIME
GetLocalTime
sys
Label1.Caption
=
Format(Date,
"yyyy年mm月dd日")
Label2.Caption
=
Time
&
":"
&
Int(CLng(sys.wMilliseconds)
/
100)
Label3.Caption
=
"距离"
&
aa
&
"还有"
&
vbCrLf
&
aa
-
Date
&
"天"
End
Sub

扩展阅读:新能源 轮候时间 计算 ... 顾比倒数线 代码 ... 手机扫一扫自动算数 ... vb倒计时5秒代码 ... 新手怎么学代码编程 ... 表格怎么去除#div0 ... python编程代码 ... 时间计算器分钟 ... 平均值#div0怎么办 ...

本站交流只代表网友个人观点,与本站立场无关
欢迎反馈与建议,请联系电邮
2024© 车视网