VBS里Err对象的使用

上一篇 / 下一篇  2008-12-04 23:58:57 / 个人分类:QTP

Err对象作为VBS里的一个固有内置全局对象,在使用时无需先创建一个对象实例。它有其属性和方法:

 

1. 属性

a) Number 默认属性

b) Source

c) HelpFile

       用法:object.HelpFile [= contextID]

d) Descrīption:当没有用户自定义Descrīption值时,该值为Number属性值

       用法:object.Descrīption [= stringexpression]

e) HelpContext

       用法:object.HelpContext [= contextID]

       If both HelpFile and HelpContext are empty, the value of the Number property is checked.

 

2. 方法

Clear:重置Err对象

Raise:产生运行错误

 

当遇到On Error Resume Nex后,Err对象的属性被重置为0或者是长度为0的字符串。

 

典型的Err对象用法:

 

On Error Resume Next

Dim Msg

Err.Clear

Err.Raise 6   ' Generate "Overflow" error.

Err.Helpfile = "yourHelp.hlp"

Err.HelpContext = yourContextID

If Err.Number <> 0 Then

   Msg = "Press F1 or Help to see " & Err.Helpfile & " topic for" & _

   " the following HelpContext: " & Err.HelpContext

   MsgBox Msg, , "error: " & Err.Descrīption, Err.Helpfile, Err.HelpContext

End If


TAG: QTP

 

评分:0

我来说两句

日历

« 2024-04-26  
 123456
78910111213
14151617181920
21222324252627
282930    

数据统计

  • 访问量: 20440
  • 日志数: 32
  • 建立时间: 2007-12-13
  • 更新时间: 2008-12-04

RSS订阅

Open Toolbar