检测到“错误:对象不支持此属性或方法”

时间:2023-01-21 19:20:00

The object I’m working on is instantiated in JavaScript, but used in VBScript. In one code path, the variable M.DOM.IPt is defined and has a value, in the other however it is not. I need to detect if it has been defined or not. I checked that M.DOM is defined and accessable in both code paths. Every test I have tried simply results in this error:

我正在处理的对象是在JavaScript中实例化的,但在VBScript中使用。在一个代码路径中,变量M.DOM.IPt被定义并具有值,而在另一个代码路径中则不是。我需要检测它是否已定义。我检查了M.DOM是在两个代码路径中定义和访问的。我尝试的每个测试都会导致此错误:

Error: Object doesn't support this property or method

错误:对象不支持此属性或方法

I have tried:

我试过了:

  • IsEmpty(M.DOM.IPt)
  • M.DOM.IPt is Nothing
  • M.DOM.IPt没什么

  • isNull(M.DOM.IPt)

Is there any way to detect the variable isn’t defined and avoid the error?

有没有办法检测变量未定义并避免错误?

Note: I can put On Error Resume Next in and it will simply ignore the error, but I actually need to detect it and conditionally do something about it.

注意:我可以将On Error Resume Next放入其中并且它将简单地忽略错误,但我实际上需要检测它并有条件地对它做一些事情。

3 个解决方案

#1


1  

    Function SupportsMember(object, memberName)
      On Error Resume Next

      Dim x
      Eval("x = object."+memberName)

      If Err = 438 Then 
        SupportsMember = False
      Else 
        SupportsMember = True
      End If

      On Error Goto 0 'clears error
    End Function

#2


1  

On Error Resume Next
Err.Clear
MyVariable=M.DOM.Ipt
If Err.Number<> 0 Then
    'error occured - Ipt not defined
    'do your processing here
Else
    'no error - Ipt is defined
    'do your processing here
End If

#3


0  

Have you tried On Error Goto label?

你试过On Error Goto标签吗?

#1


1  

    Function SupportsMember(object, memberName)
      On Error Resume Next

      Dim x
      Eval("x = object."+memberName)

      If Err = 438 Then 
        SupportsMember = False
      Else 
        SupportsMember = True
      End If

      On Error Goto 0 'clears error
    End Function

#2


1  

On Error Resume Next
Err.Clear
MyVariable=M.DOM.Ipt
If Err.Number<> 0 Then
    'error occured - Ipt not defined
    'do your processing here
Else
    'no error - Ipt is defined
    'do your processing here
End If

#3


0  

Have you tried On Error Goto label?

你试过On Error Goto标签吗?