vb容错语句是什么?
答案:2 悬赏:30 手机版
解决时间 2021-01-25 05:47
- 提问者网友:龅牙恐龙妹
- 2021-01-25 01:39
vb容错语句是什么?
最佳答案
- 五星知识达人网友:十年萤火照君眠
- 2021-01-25 02:27
1.使用on error goto语句
在代码首行加入on error goto语句,如:
'...
On Error Goto err_1 '如果出错程序将按标志跳转到指定语句执行
Shell "C:\Program Files\TENCENT\QQ\QQ.exe"
Exit Sub
err_1: Msgbox Err.Description
或者:
On Error Resume Next '如果使用本语句程序如果出错则将会转到出错语句的下一句继续执行
Shell "C:\Program Files\TENCENT\QQ\QQ.exe"
在代码首行加入on error goto语句,如:
'...
On Error Goto err_1 '如果出错程序将按标志跳转到指定语句执行
Shell "C:\Program Files\TENCENT\QQ\QQ.exe"
Exit Sub
err_1: Msgbox Err.Description
或者:
On Error Resume Next '如果使用本语句程序如果出错则将会转到出错语句的下一句继续执行
Shell "C:\Program Files\TENCENT\QQ\QQ.exe"
全部回答
- 1楼网友:枭雄戏美人
- 2021-01-25 02:38
3种方法: 1.使用on error goto语句 在代码首行加入on error goto语句,如: '... on error goto err_1 '如果出错程序将按标志跳转到指定语句执行 shell "c:\program files\tencent\qq\qq.exe" exit sub err_1: msgbox err.description 或者: on error resume next '如果使用本语句程序如果出错则将会转到出错语句的下一句继续执行 shell "c:\program files\tencent\qq\qq.exe" 2.先判断有无文件存在(即:anybody方法) if dir("c:\program files\tencent\qq\qq.exe") = "" then msgbox "文件不存在!" else shell "c:\program files\tencent\qq\qq.exe" end if 3.使用api来获取指定程序的绝对路径 private declare function searchtreeforfile lib "imagehlp.dll" (byval lproot as string, byval lpinpath as string, byval lpoutpath as string) as long 'api函数声明 private declare function getdrivetype lib "kernel32" alias "getdrivetypea" (byval ndrive as string) as long function searchfile(byval filename as string) as string dim r as long, i as long, searchpath as string for i = 0 to 25 searchpath = chr$(i + 65) & ":\" if getdrivetype(searchpath) = 3 then searchfile = string$(1024, 0) r = searchtreeforfile(searchpath, filename, searchfile) if r <> 0 then searchfile = split(searchfile, chr(0))(0): exit function end if next searchfile = "" end function private sub command1_click() dim filepath as string filepath = searchfile("qq.exe") if filepath = "" then msgbox "文件不存在!" else shell filepath & "\qq.exe" end if end sub
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯