Forum Discussion

softwarevikram's avatar
softwarevikram
Occasional Contributor
11 years ago

How to handle "Exists" property? It throws "error" when certain object doesn't exist instead of throwing it as "False"

Consider the below scenario

**********

If object.Exists Then

   'Action to be done when object is present

Else

   'Action to be done when object is not present

End If

**********

Problem: while 'm trying to perform "Else" part actions, it is preceeded by an "Error Log" where as i don't want that to be an error instead i want to perform some action in that else part without error log. How could i do this?



Expecting solutions & suggestions from my dear professionals!
  • sbkeenan's avatar
    sbkeenan
    Frequent Contributor
    Hi Vikraman



    I think you need to use one of the waitChild/waitAliasChild type methods.



    When checking the Exists property of an object, if that object doesn't exist, teh Exists property, by definition, doesn't exist either, hence your error in the log file.



    If you're your using Aliases, then use the waitAliasChild method, something like this:





    If (<processName>.waitAliasChild("<objectName>", 5000).Exists)

       'do something here

    Else

       'Object doesn't exist - do something else here

    End If





    Basically, the above waitAliasChild method will check for the existence of the object and will continue to do so for 5 seconds.  If after 5 seconds, the object doesn't exist, a stub object with only one property (the Exists property) is returned, which will be set to false, meaning that the statements in the Else clause will be executed.  If, however, the object is found within the 5 second time limit, the script will immediately act on the appropriate statements for teh 'true' part of the If statement.



    Hope this helps.



    Regards

    Stephen.