请问怎么编程:按Command1按钮300秒后,将窗口隐藏。下面的代码,我一运行,按Command1按钮,窗口就隐藏,感觉就没有计时间。Option ExplicitPrivate Sub Command1_Click()
     Timer1_Timer
     Form1.Hide
End SubPrivate Sub Timer1_Timer()
    Timer1.Interval = 300
End Sub

解决方案 »

  1.   

    timer不是那么用的
    gettickcount的API声明自己找private sub command1_click()
    dim l as long
    l=gettickcount()
    do
    doevents
    loop until gettickcount()-l>=300000
    me.hide
    end sub
      

  2.   

    timer的用法
    timer1的enable属性初始化为falsePrivate Sub Command1_Click()
         timer1.interval=1000
         timer1.enable=true
    End SubPrivate Sub Timer1_Timer()
        static i as integer
        i=i+1
        if i>=300 then
            timer1.enable=false
            me.hide
        end if
    End Sub
      

  3.   

    如下修改:计数器初始值为0,为停止状态。Private Sub Command1_Click()
         Timer1.Interval = 30000‘启动计数30秒
    End SubPrivate Sub Timer1_Timer()
        timer1.Interval = 0 ‘30秒后计数停止,如果控制300秒,需要增加一个控制变量
        form1.hide          ‘隐藏form1
    End Sub
      

  4.   

    Option Explicit
    Dim i As IntegerPrivate Sub Command1_Click()
       Timer1.Interval = 1000
       
    End SubPrivate Sub Timer1_Timer()
       
       i = i + 1
       If i > 10 Then
        Me.Hide
       End If
    End Sub
      

  5.   

    Option Explicit
    Dim i As IntegerPrivate Sub Command1_Click()
    Timer1.Interval = 1000
    Timer1.enabled=true
    End SubPrivate Sub Timer1_Timer()i = i + 1
    If i > 300 Then
    Me.Hide
    i=0
    timer1.enabled=false
    End If
    End Sub