Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks.

Go Back   Vista Forums > Misc Newsgroups > VB Script

Vista - What value should Err.Number be if there's no error

Reply
 
Old 10-08-2008   #1 (permalink)
Andrew Falanga


 
 

What value should Err.Number be if there's no error

Hi,

It may sound like a dumb question but if there's no error condition
what value should I expect to find? Should it be zero?

Andy

My System SpecsSystem Spec
Old 10-08-2008   #2 (permalink)
mayayana


 
 

Re: What value should Err.Number be if there's no error

> It may sound like a dumb question but if there's no error condition
Quote:

> what value should I expect to find? Should it be zero?
>
Yes, it's zero. You can also clear the error
to makr sure it's zero before an operation by
using Err.Clear.


My System SpecsSystem Spec
Old 10-08-2008   #3 (permalink)
Al Dunbar


 
 

Re: What value should Err.Number be if there's no error


"mayayana" <mayaXXyana@xxxxxx> wrote in message
news:euh%23m8YKJHA.740@xxxxxx
Quote:
Quote:

>> It may sound like a dumb question but if there's no error condition
>> what value should I expect to find? Should it be zero?
>>
> Yes, it's zero. You can also clear the error
> to makr sure it's zero before an operation by
> using Err.Clear.
And, logically, the reason the success condition maps to zero is simplicity
itself:

if err.number then
wscript.echo "an error occurred"
else
wscript.echo "NO error occurred"
end if

When treated as a boolean, err.number takes on the value "an error has
occurred", as zero is interpreted as false, whereas all non-zero values are
interpreted as true.

/Al


My System SpecsSystem Spec
Old 10-09-2008   #4 (permalink)
Andrew Falanga


 
 

Re: What value should Err.Number be if there's no error

On Oct 8, 3:47*pm, "mayayana" <mayaXXy...@xxxxxx> wrote:
Quote:
Quote:

> > It may sound like a dumb question but if there's no error condition
> > what value should I expect to find? *Should it be zero?
>
> * Yes, it's zero. You can also clear the error
> to makr sure it's zero before an operation by
> using Err.Clear.
Thanks for the response. Then this conditional should not be true:

If Err.Number = Empty Then
MsgBox "Err.Number is empty"
End If

Right? If this is right, what does it mean if the condition is true
as I'm seeing in my environment?

Andy
My System SpecsSystem Spec
Old 10-09-2008   #5 (permalink)
mayayana


 
 

Re: What value should Err.Number be if there's no error

Empty is not numeric. It tests for an uninitialized
variable. Err.Number is numeric. I think you may have
just come across a quirk due to wrong syntax.

You can use:
If Err.Number = 0 Then

And as Al pointed out, if you prefer terse code you
can also use:

If Err.Number Then '-- true if Err.Number <> 0

or

If Not Err.Number Then '-- True if Err.Number = 0

I just tried this code:

MsgBox IsEmpty(Err.Number)
'-- Empty = 9
MsgBox Err.Number = Empty

It returns False, True -- as you pointed out.
I think maybe the third line is being interpreted
by seeing "Empty" as a numeric variable. So 0 = 0. True.
Yet if I uncomment the second line it causes an error
because Empty is a keyword. So what you found doesn't
really make sense. But it's also not relevant, since Empty
is not applicable to Err.Number. (Err.Number is a property
of the Err object, so it can't be an uninitialized variable.)
Just treat Err.Number as a numeric value and you'll be fine.
Quote:

>
Thanks for the response. Then this conditional should not be true:

If Err.Number = Empty Then
MsgBox "Err.Number is empty"
End If

Right? If this is right, what does it mean if the condition is true
as I'm seeing in my environment?

Andy


My System SpecsSystem Spec
Old 10-09-2008   #6 (permalink)
Andrew Falanga


 
 

Re: What value should Err.Number be if there's no error

On Oct 9, 9:56*am, "mayayana" <mayaXXy...@xxxxxx> wrote:
Quote:

> * Empty is not numeric. It tests for an uninitialized
> variable. Err.Number is numeric. I think you may have
> just come across a quirk due to wrong syntax.
>
> You can use:
> If Err.Number = 0 Then
>
> And as Al pointed out, if you prefer terse code you
> can also use:
>
> If Err.Number Then *'-- true if Err.Number <> 0
>
> or
>
> If Not Err.Number Then *'-- True if Err.Number = 0
>
> I just tried this code:
>
> MsgBox IsEmpty(Err.Number)
> '-- Empty = 9
> MsgBox Err.Number = Empty
>
> It returns False, True -- as you pointed out.
> I think maybe the third line is being interpreted
> by seeing "Empty" as a numeric variable. So 0 = 0. True.
> Yet if I uncomment the second line it causes an error
> because Empty is a keyword. So what you found doesn't
> really make sense. But it's also not relevant, since Empty
> is not applicable to Err.Number. (Err.Number is a property
> of the Err object, so it can't be an uninitialized variable.)
> Just treat Err.Number as a numeric value and you'll be fine.
>
Ok, I tried the comparison to Empty because nothing else was making
sense (this could be mostly due to my ignorance of VBScript). I was
trying to see the contents of this property via:

MsgBox "Current Error Number: " & CStr(Err.Number)

Which was printing, "Current Error Number: ". Notice that lack
of a number. Since this is a numerical value field, and can't be
uninitialized, why would I see nothing when doing this? Just to make
sure I was using the CStr function correctly, I did this:

anInt = 99
MsgBox "An Int: " & CStr(anInt)

Which appropriately printed, "An Int: 99." So, what's going on?

Andy
My System SpecsSystem Spec
Old 10-09-2008   #7 (permalink)
mayayana


 
 

Re: What value should Err.Number be if there's no error

>
Ok, I tried the comparison to Empty because nothing else was making
sense (this could be mostly due to my ignorance of VBScript). I was
trying to see the contents of this property via:

MsgBox "Current Error Number: " & CStr(Err.Number)
Quote:

>
I don't know what the trouble might be there. It
prints 0 for me.


My System SpecsSystem Spec
Old 10-13-2008   #8 (permalink)
Andrew Falanga


 
 

Re: What value should Err.Number be if there's no error

On Oct 9, 3:02*pm, "mayayana" <mayaXXy...@xxxxxx> wrote:
Quote:

> Ok, I tried the comparison to Empty because nothing else was making
> sense (this could be mostly due to my ignorance of VBScript). *I was
> trying to see the contents of this property via:
>
> MsgBox "Current Error Number: " & CStr(Err.Number)
>
>
>
> * I don't know what the trouble might be there. It
> prints 0 for me.
Well, I found the source of my problem . . . it was between the
keyboard and the chair. As I mentioned before, I'm a complete
VBScript neophyte and it showed on this one. The problem was that I
was redefining the err object, unwittingly. I didn't know that
VBScript isn't case sensitive (all other languages I've written in
thus far are) and I had this statement at the beginning of my script:

Dim err

This accounts for why I was getting "empty" variables instead of
numbers, etc.

Thanks for the help,
Andy
My System SpecsSystem Spec
Reply

Thread Tools


Similar Threads
Thread Forum
Help with windows vista mail, Socket Error: 10053, Error Number: 0x800CCC0F Vista mail
no,socket Error: 11003. Error Number: 0x800CC0D cant i send email name is correctly Vista mail
Socket Error: 10060, Error Number: 0x800CCC0E for VALID POP Server Vista mail
Canot post to newsgroups Socket Error: 10053, Error Number: 0x800CCC0F Vista mail
Canot post to newsgroups Socket Error: 10053, Error Number: 0x800CCC0F Vista General


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46