我的代码是这样的,那位帮我看看怎么改改.需求就是每30分钟执行一次60分钟执行一次,一直这样循环.也就是90分钟的时候要执行回30分钟的东西,但是现在的问题是30当时60的倍数老是在执行30的代码而不执行60的.Private Sub Timer1_Timer()
'设置时钟为30000
Static n As Integer
n = n + 1
If n Mod 60 = 0 Then '30分钟
Label1.Caption = "温馨提示:30分钟"
End If
If n Mod 120 = 0 Then '60分钟
Label1.Caption = "温馨提示:60分钟"
End If
End Sub
'设置时钟为30000
Static n As Integer
n = n + 1
If n Mod 60 = 0 Then '30分钟
Label1.Caption = "温馨提示:30分钟"
End If
If n Mod 120 = 0 Then '60分钟
Label1.Caption = "温馨提示:60分钟"
End If
End Sub
Private Sub Timer1_Timer()
'设置时钟为30000
n = n + 1
If n = 30 Then '30分钟
Label1.Caption = "温馨提示:30分钟"
End If
If n = 60 = 0 Then '60分钟
Label1.Caption = "温馨提示:60分钟"
n = 0
End If
End Sub
vbman2003的代码也没实验成功.
Timer1.Interval = 1000
End SubPrivate Sub Timer1_Timer()
n = n + 1
If n = 30 * 60 Then '30分钟
Label1.Caption = "温馨提示:30分钟"
End If
If n = 60 * 60 Then '60分钟
Label1.Caption = "温馨提示:60分钟"
n = 0
End If
End Sub
Static n As Integer
n = n + 1
If n Mod 120 = 0 Then '60分钟
Label1.Caption = "温馨提示:60分钟"
n=0
elseIf n Mod 60 = 0 Then '30分钟
Label1.Caption = "温馨提示:30分钟"
End If
Private Sub Timer1_Timer()
'设置时钟为60000(1分钟)
Static n As Integer
n = n + 1
select case n
case 30: Label1.Caption = "温馨提示:30分钟"
case 60
n=0
Label1.Caption = "温馨提示:60分钟"
end select
End Sub
n=(n+1) mod 60
select case n
case 0: xxxxx
case 30: xxxxx
end select
如果不设置,可能几天后n产生溢出ls的n=(n+1) mod 60也是不错的.就是n不要超过60了
if ntimesec=1800 then '到了30分钟了
ntimesec=0
nstate=nstate+1 '状态加1 select case nstate '判断状态
case 1
do 30min
case 3
do 60min
nstate=0
end select
end if
经过优化还可以使用一个变量,但是这样子结构很容易明白了.
Option Explicit
Dim intP As Integer
Dim strTime As String
Private Sub Form_Load()
Timer1.Interval = 1000
Timer1.Enabled = True
strTime = Now
intP = -1
End SubPrivate Sub Timer1_Timer()
If DateDiff("s", strTime, Now) >= 30 Then
strTime = Now
intP = (intP + 1) Mod 3
End If
If intP = 0 Then
'执行30分、90分钟的代码
ElseIf intP = 2 Then
'执行60分钟的代码
End If
End Sub
Dim n As LongPrivate Sub Form_Load()
Timer1.Interval = 1000
End SubPrivate Sub Timer1_Timer()
n = n + 1
If n = 30 * 60 Then '30分钟
Label1.Caption = "温馨提示:30分钟"
End If
If n = 60 * 60 Then '60分钟
Label1.Caption = "温馨提示:60分钟"
n = 0
End If
End Sub
[/code]