检查对象在VBScript中存在 [英] Check if an Object exists in VBScript

查看:101
本文介绍了检查对象在VBScript中存在的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我保持由外部公司写在VB脚本一个经典的ASP应用很久很久以前。

I'm maintaining a Classic ASP app written in VB Script by an outside company long, long ago.

我的镜像文件路径的数组,像这样:

I have an array of imagefile paths, like so:

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"

这将只存在于有横幅广告的网页。有一些标准的code,通过这个列表中迭代一个包含文件(适用于所有页面)。

This will exist ONLY on pages that have banner ads. There is some standard code that iterates through this list in an include file (common to all pages).

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

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

The problem is that if banners is not instantiated on the page (it's not on all pages), I get a Can't find object error

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

What's the proper way to check if an object exists in VB Script?

推荐答案

@ ATOMIX:替换

@Atømix: Replace

If Not banners Is Nothing then 

和使用

If IsObject(banners) Then 

您其他code则可以放入一个包含文件,并在你的页面的顶部使用,以避免不必要的重复。

Your other code you can then place into an include file and use it at the top of your pages to avoid unnecessary duplication.

@Cheran学生:我测试了我的片段以上选项显式开启/关闭,并没有遇到错误的任一版本,无论的昏暗的横幅在那里与否。 : - )

@Cheran S: I tested my snippets above with Option Explicit on/off and didn't encounter errors for either version, regardless of whether Dim banners was there or not. :-)

这篇关于检查对象在VBScript中存在的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆