VB 判断变量的值

来源:百度知道 编辑:UC知道 时间:2024/05/24 18:21:18
a的值不是1 就是0 现在判断,什么时候 a从1为0 就msgbox"错误" 如果程序启动的时候 a 的值本身就是0 则不报错。。也就是一个跳变的过程。

举例:程序启动 a = 0 这个时候a的值为1了,然后又为0 则报错。

Sub Timer1_timer
static lastvalue
if a <> lastvalue and a = 0 then
MSGBOX "错误"
end if
lastvalue = a
end sub

用定时器啊,在程序启动时,不开启定时器,等启动完毕才开定时器,在定时器里面检查a值跳变。

form_load 事件中写:
timer1.enable=true

timer1_timer 事件里写:
if a = 0 then msgbox "错误"

当然timer1.enable属性开始要设为false,而且a至少要是模块级变量

Private Sub Timer1_Timer()
if a=0 then msgbox "错误"
End Sub