自己做的一个小事物提醒程序
为什么到
InStr(CDate(Now()), CDate(Str_Tm)) 比较的时候
怎么都不提示了??Private Sub Command1_Click()
MyText = "C:\Time.ini"
StrSer = "[" + Text1.Text + "-" + Text2.Text + "-" + Text3.Text + " " + Text4.Text + "]" + Chr(9) + "{" + Text5.Text + "}"
Open MyText For Output As #1
Print #1, StrSer
Close #1
End SubPrivate Sub Form_Load()
Timer1.Interval = 1000
Text1.Text = Year(Date)
Text2.Text = Month(Date)
Text3.Text = Day(Date)
Text4.Text = Time()
MyText = "C:\Time.ini"
Open MyText For Input As #1
Do While Not EOF(1)
Line Input #1, StrSer
Loop
Close #1
Str = StrSer
Tm_arr = Split("Test" & Replace(Str, "[", "]") & "Test", "]")
Str_Tm = Tm_arr(1)
End SubPrivate Sub Timer1_Timer()
Label1.Caption = Now()
If InStr(CDate(Now()), CDate(Str_Tm)) <> 0 Then
MsgBox Str_Tm
End If
End Sub
为什么到
InStr(CDate(Now()), CDate(Str_Tm)) 比较的时候
怎么都不提示了??Private Sub Command1_Click()
MyText = "C:\Time.ini"
StrSer = "[" + Text1.Text + "-" + Text2.Text + "-" + Text3.Text + " " + Text4.Text + "]" + Chr(9) + "{" + Text5.Text + "}"
Open MyText For Output As #1
Print #1, StrSer
Close #1
End SubPrivate Sub Form_Load()
Timer1.Interval = 1000
Text1.Text = Year(Date)
Text2.Text = Month(Date)
Text3.Text = Day(Date)
Text4.Text = Time()
MyText = "C:\Time.ini"
Open MyText For Input As #1
Do While Not EOF(1)
Line Input #1, StrSer
Loop
Close #1
Str = StrSer
Tm_arr = Split("Test" & Replace(Str, "[", "]") & "Test", "]")
Str_Tm = Tm_arr(1)
End SubPrivate Sub Timer1_Timer()
Label1.Caption = Now()
If InStr(CDate(Now()), CDate(Str_Tm)) <> 0 Then
MsgBox Str_Tm
End If
End Sub
用DateDiff()day() hour() ...等日期时间函数多好啊
Public str_Tm as String
我都加了
不管用
好像到时间都不执行一样
如果
我把 str_Tm 换成 "2006-12-11 14:04:15"
他到这个时间会提示
Label1.Caption = Now()
If CDate(Now())>= CDate(Str_Tm) Then
Timer1.enabled=false
MsgBox Str_Tm
End If
End Sub
*****************************************************************************
欢迎使用CSDN论坛阅读器 : CSDN Reader(附全部源代码)
http://www.cnblogs.com/feiyun0112/archive/2006/09/20/509783.html
MsgBox Str_Tm
End If不知道LZ要怎样比较时间,上面的语句没太大问题,除了Instr的参数类型不对外。但是很难执行,因为str_tm设定的时间很难与Now匹配上,除非你的Timer的间隔设置为1ms。
这样不行啊
If InStr(CDate(Now()), CDate(Str_Tm)) <> 0 Then怎么比较都行
最终目的就是想让
Now()的时间和Time.ini中设定的时间一样时提示一下就行了
If Now = CDate(Str_Tm) Then试试。
或者,你用datediff,但比较时,最好不用=,而用>=
我已经找到问题了
我每次点击 Command1_Click() 修改 C:\Time.ini里面的值以后
因为 Form_Load() 不会刷新
所以Str_Tm获得的还是C:\Time.ini里面上一次的值
所以怎么对比也不会正确呵呵!