都不知道你想干什么?doevents也许可以用,不过如果说执行一行语名后赋一个值给变量得那么麻烦嘛?反正程序执行时都是从上到下的dim i as integer i=1 msgbox i i=2 msgbox i
把你想做的事做成一个过程或函数,然后在timer事件中等条件一满足就调用它
例子:Private Sub Command1_Click() Timer1.Enabled = True End SubPrivate Sub Timer1_Timer() Static a a = a + 1 If a > 100 Then test Timer1.Enabled = False End If End SubSub test() MsgBox "条件满足,可以做你想要做的事了。" End Sub
用一个DO LOOPTIME中用一个全局变量DO if 全局变量=1 then exit do loop
要注意由于vb是单线程执行,所以加DoEvents一定是必要的。
执行 (语句 N) Do DoEvents Loop Until CanResumeNext ' (=True) 执行 (语句 N+1)Private Sub Timer1_Timer()
要等待数值时,启动Timer2,间隔一定时间查一下所查变量,如果变化了,就执行你想用的代码吧
DoEvents
Loop Until i = 10
i=1
msgbox i
i=2
msgbox i
Timer1.Enabled = True
End SubPrivate Sub Timer1_Timer()
Static a
a = a + 1
If a > 100 Then
test
Timer1.Enabled = False
End If
End SubSub test()
MsgBox "条件满足,可以做你想要做的事了。"
End Sub
if 全局变量=1 then exit do
loop
执行 (语句 N)
Do
DoEvents
Loop Until CanResumeNext ' (=True)
执行 (语句 N+1)Private Sub Timer1_Timer()
CanResumeNext=True
End Sub