加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > asp.Net > 正文

asp-classic – 检查VBScript中是否存在Object

发布时间:2020-12-15 22:59:06 所属栏目:asp.Net 来源:网络整理
导读:很久以前,我正在外部公司维护一个用VB Script编写的经典ASP应用程序. 我有一系列的图像文件路径,像这样: dim banners,arrKeys,iset banners=CreateObject("Scripting.Dictionary")banners.Add "banner1.jpg","http://www.somelink.com"banners.Add "banner2
很久以前,我正在外部公司维护一个用VB Script编写的经典ASP应用程序.

我有一系列的图像文件路径,像这样:

dim banners,arrKeys,i
set banners=CreateObject("Scripting.Dictionary")
banners.Add "banner1.jpg","http://www.somelink.com"
banners.Add "banner2.jpg","http://www.somelink.com"
banners.Add "banner3.jpg","http://www.somelink.com"

这只会在具有横幅广告的网页上存在.有一些标准代码可以在包含文件(通用于所有页面)中遍历此列表.

If Not banners Is Nothing then 
  ' then loop through the Dictionary and make a list of image links
End if

问题是如果横幅没有在页面上实例化(不在所有页面上),我得到一个无法找到对象错误

检查VB脚本中是否存在对象的正确方法是什么?

解决方法

@At?mix:替换
If Not banners Is Nothing then

并使用

If IsObject(banners) Then

您的其他代码可以放在一个包含文件中,并在页面顶部使用它,以避免不必要的重复.

@Cheran S:我使用Option Explicit开启/关闭测试了我的片段,并且没有遇到任何版本的错误,无论Dim横幅是否存在.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读