Forum Discussion
1 Reply
- AlexKarasChampion Level 3
Hi,
> i got error on 1st line
Not sure what line is first...
My guess is that the first one is the line with the IF condition.
If my guess is correct, then this is expected behavior of VBScript.
VBScript does not have short logical expressions evaluation circuit and always executes the complete one. This means that if the given object does not exist then obj.Visible clause will be evaluated (because it is first in the condition and because of the full evaluation) and will post an error because there is no Visible property in the non-existing object.
The correct implementation for VBScript is like this:
If (obj.Exists) Then If (obj.Visible) Then ... Else ' object is not visible but exists End If Else ' object does not exist End If
Note 1:
For the languages that support short evaluation, the correct implementation is to specify .Exists check to be the first one in the condition:
if (obj.Exists && obj.Visible) then // object exists and is visible else // there will be no error if the object does not exist because .Visible will not be evaluated
Note 2: It is not recommended to explicitly compare boolean values to either True or False in the if() clauses.
Related Content
Recent Discussions
- 20 hours agojstaehlin
- 2 days agoAivanitskiy