Err 的用法出现的问题和解决方法

时间:2025-03-04 09:09:54

在一个方法中使用

function act(formula)

dim temp as varient

temp=evaluate(formula)

if Err>0 then‘

    处理代码

end

end function

 

这里 Err是一个全局变量,即使act()方法中未出现错误,Err参数也可能出现不为0的情况,因为其他方法可能报错并隐藏了错误,但未将Err置0处理

 

解决方法:

  临时:是在act方法的开始加 Err=0

 正式:在所有的方法中如果隐藏错误,如On Error Resume next  则需要加入Err=0