Determining the status of an object using Or conditional operator

I've created the following objects in a VBScript:
            Set oLocator = CreateObject("WbemScripting.SWbemLocator")
            Set oService = oLocator.ConnectServer(sServer, "root\Default", strDom & "\" & strUser, strPass)
            Set oReg = oService.Get("StdRegProv")
Now, I've seen it were the variable is "uninitialized" (empty) or the object doesn't get created and it's equivalent to "Nothing" so I decided to use the Or conditional operator and my findings are a bit confusing. If I write it like this:
If Not (IsEmpty(oReg)) Or Not ((oReg) Is Nothing) Then
     // do this
     // do that
end if
So, when I came across toe oReg object = Nothing it didn't jump down to the else statement as if there oReg object wasn't equal to Nothing. Now, if I put it on separate lines like this it works:
If Not IsEmpty(oReg) Then
   If Not (oReg) Is Nothing
   End If
End If
What's the point of using "Or" if it doesn't work when it should work? I also come across this very problem with using IsNull "Or" IsEmpty as well. It's frustrating.
Maybe one of you experts can clue me in on some syntax I've not discovered  yet. Thanks,
Who is Participating?
Daz_1234Connect With a Mentor Commented:
The If condition will only get to Else if both sides of the 'Or' are False.  If either are True then the first bit before Else is run.

This sounds obvious, but in your code, the only way for both sides of the 'Or' to be False is if oReg is both Empty and Nothing.  This is impossible.

When oReg is Nothing, it is also Not Empty, so the If statement is still True and the main condition will run.

Patrick MatthewsCommented:
When combining boolean statements like that, be careful with parentheses.

Does this work?

If (not isempty(oreg)) or (not oreg is nothing) then
End if
wally_davisAuthor Commented:
<sigh>, no that didn't work.
Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

wally_davisAuthor Commented:
I've tried just about every parenthesis position and still it doesn't work. hmmm
wally_davisAuthor Commented:
I would like to see a really good article written on how one decides to check for data and which one would be a priority over the other using all these different functions:
Is Nothing
That is to say, should I always check for an "Empty" uninitialized variable first, then check if it is NULL data and so on. I think Is Nothing "is nothing" more than checking to see if an object was set / instantiated.
wally_davisAuthor Commented:
Been so long I can't remember.
All Courses

From novice to tech pro — start learning today.