Detect "Error: Object does not support this property or method"

The Im object working on is created in JavaScript, but used in VBScript. In one code path, a variable is M.DOM.IPtdefined and has a value, and in another it is not. I need to determine if this has been determined or not. I checked that it M.DOMis defined and available for both code paths. Every test I tried just leads to this error:

Error: object does not support this property or method

I tried:

  • IsEmpty(M.DOM.IPt)
  • M.DOM.IPt is Nothing
  • isNull(M.DOM.IPt)

Is there a way to detect the isnt variable and avoid the error?

Note. I can put it On Error Resume Nextinside and it will simply ignore the error, but I really need to detect it and conditionally do something.

+3
source share
3
    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
+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
+1

Have you tried the label "Error on Goto"?

0
source

Source: https://habr.com/ru/post/1698927/


All Articles