我的代码是这样的,那位帮我看看怎么改改.需求就是每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

解决方案 »

  1.   

    Dim n as Long
    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
      

  2.   

    如果n Mod 120 = 0,则n Mod 60 = 0
      

  3.   

    abc612008的方法不行.还是老执行第一个IF.
    vbman2003的代码也没实验成功.
      

  4.   

    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
      

  5.   


    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
      

  6.   

    还要mod干吗,直接:
    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
      

  7.   

    基本就是这个意思:
    n=(n+1) mod 60
    select case n
         case 0:   xxxxx
         case 30:  xxxxx
    end select
      

  8.   

    因为你设计的是30.60分钟,所以在60分钟的时候,条件达到后应该重新设置n=0.
    如果不设置,可能几天后n产生溢出ls的n=(n+1) mod 60也是不错的.就是n不要超过60了
      

  9.   

    简单的状态机编程啊.两种状态,也就是三进制罗!那设置为每30分钟加1,到3后置零.再用个select case来切换这个状态变量,为1时执行30分钟该做的事,为3时执行60分钟的事!static nTimeSec as long,nState as longntimesec=ntimesec+1     '这个是一秒一次
    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
    经过优化还可以使用一个变量,但是这样子结构很容易明白了.
      

  10.   


    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
      

  11.   

    [code=VBE]
    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]