当前位置: 移动技术网 > IT编程>脚本编程>VBScript > VBS基础篇 Err对象

VBS基础篇 Err对象

2018年08月08日  | 移动技术网IT编程  | 我要评论

ca1759,东莞妇幼保健院预约,抒情诗句

err对象是一个具有全局范围的内部对象,含有关于错误的所有信息。

on error resume next 忽略运行时产生的所有错误

on error goto 0 取消忽略错误措施

主要方法有:clear、raise
主要属性有:description、helpcontext、helpfile、number、source

其属性及方法的详细说明见下面的示例说明:

err对象的方法

clear

描述:清空err对象当前所有的属性,也就是清空错误
语法:err.clear
示例:

on error resume next '忽略运行时产生的所有错误
msgbox 5/0
msgbox err.number '输出错误的数值
err.clear '清空所有的错误信息
msgbox err.number '输出0

raise

描述:定义一个运行时的错误
语法:err.raise(number,source,description,helpfile,helpcontent)
参数:number:用于标记错误号
source 标记产生错误的对象或者应用程序名称
description:关于错误的描述信息
helpfile:help文件的有效路径
helpcontent:help文件的主题
示例:  

on error resume next
err.raise 22,"vbs脚本","溢出啦","c:\test.txt" '定义一个运行时的错误
msgbox "错误:" & vbcrlf _
    & "number:" & err.number & vbcrlf _
    & "source:" & err.source & vbcrlf _
    & "description:" & err.description & vbcrlf _
    & "helpfile:" & err.helpfile
err.clear '清除错误

err对象的属性

  description

描述:返回或者设置error的描述
语法:description(conid)
示例:

desc = err.description '返回error的描述信息
err.description = "类型不匹配" '设置error的描述信息

helpcontext

描述:返回或者设置指定帮助信息的主题
语法:helpcontext(string)

示例:

helpcontext = err. helpcontext '返回error的帮助主题
err. helpcontext = "类型不匹配" '设置error的帮助主题

helpfile

描述:返回或者设置help文件的地址
语法:helpfile(filepath)
示例:

helpfile = err. helpfile '返回helpfile的地址
err. helpfile = "c:\test.txt" '设置helpfile的地址

number

描述:返回或者设置一个表示错误的数值
语法:number(errid)
示例:

number = err. number '返回error的id
err. number = "c:\test.txt" '设置error的id

source

描述:返回或者设置报告错误的对象(或者应用程序的名称)
语法:source(string)
示例:

source = err. source '返回error的对象或者应用程序名称
err. source = "box" '设置error的对象或者应用程序名称

如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复

相关文章:

验证码:
移动技术网