
comparisons between decimal and hex values doesn't seem to work
Hi,
the HRESULT return codes like OLE-DB error 0x80040E09 "Permission denied"
are equivalent to VB 32-bit signed integers, here -2147217911 whereas
JScript follows the ECMA implementing IEEE754 floating point format which
has a mantissa of +- 2^53 (unsigned!).
Here is my error interpretation function from a previous message that
compensates this:
// hide the current scripting host
//
****************************************************************************
function writeln(s) { WScript.Echo(s) } // WSH *
// function writeln(s) { Response.Write(s) } // ASP *
// function writeln(s) { document.write(s + '\n') } // DOM *
//
****************************************************************************
// -------------------------------------------------------------------------
---
// constructor function
//
// HRESULT format definition from:
// http://msdn.microsoft.com/library/sdkdoc/com/error_5g6r.htm
// -------------------------------------------------------------------------
---
function ErrorCode(n) {
// convert the number to a 32-bit quantity fitting into the mantissa
var errorCode = ((n < 0) ? n + Math.pow(2, 32) : n) & 0xffffffff;
// unsigned to signed integer
this.error = (n > Math.pow(2, 31) - 1) ? n - Math.pow(2, 32) : n;
// bit 31
this.severity = errorCode >>> 31;
// bits 30 .. 27 are reserved for R, C, N, r
// bits 26 .. 16
this.facility = errorCode >>> 16 & 0x07ff;
// bits 15 .. 0
this.code = errorCode & 0xffff;
Quote:
}
// test sample (to be used in a try / catch stmt)
var ec = new ErrorCode(0x80040e14);
writeln('error = ' + ec.error);
writeln('severity = ' + ec.severity);
writeln('facility = ' + ec.facility);
writeln('code = ' + ec.code);
Eberhard
Quote:
> Check the types of the things you're testing. With the implicit type
> conversions that are going on, sometimes you're comparing a string with a
> number, etc.
> > I know this sounds crazy but when I compare a variable with a value in
it
> to
> > the value in hex form (0x...) the comparison fails even though I know
that
> > this comparison is true. When I compare it to the same value in decimal
> > form, the comparison succeeds. What the hell? Is there something wrong
> > with the current version of JScript that I can fix by getting a patch or
> > something?
> > please respond to the address as I do not check newsgroups often.
> > any help appreciated,
> > brian