Forums

Welcome Guest Search | Active Topics | Members

PRB: JScript returns overflow error on numbers like 0xFFnnnnnn Options
Fedor
Posted: Monday, September 30, 2002 6:28:00 AM

Rank: Advanced Member
Groups: Administration , Member

Joined: 7/28/2003
Posts: 1,140
Points: -396
Location: WA, US
Description

Sometimes when working in JScript, you can face the challenge: assigning such numbers as 0xFFnnnnnn (for example color properties of Graphics Processor, which you must set in ARGB format; first two digits are often FF to describe opaque color) causes overflow error. For example the following code will cause this error:

Code:
[JScript]
<%
var oDrawingTool
oDrawingTool = Server.CreateObject("GraphicsProcessor2002.DrawingTool");
oDrawingTool.DefaultPen.Color = 0xFF0000FF; // Blue color

// ... other code is skipped for brevity %>


Reason

The problem is that JScript assumes that oDrawingTool.DefaultPen.Color has type signed long (which cannot be larger than 0x7FFFFFFF) and numbers which are larger than 0x7FFFFFFF has type unsigned long.

Solution

Unfortunately JScript does not provide standard ways to cast from unsigned to signed types. However there some workarounds:

1. You can use negative numbers. For example 0xFFFFFFFF is the same as -1. However it is very inconvenient.

2. Applying bitwise operations can help. When we use some bitwise operation and one of operands is signed, another is unsigned, the result is signed. So to get 0xFF0000FF we can use the following operation: (0x0F0000FF | 0xF0000000). The code will be the following:

Code:
[JScript]
<%
var oDrawingTool
oDrawingTool = Server.CreateObject("GraphicsProcessor2002.DrawingTool");
oDrawingTool.DefaultPen.Color = 0x0F0000FF | 0xF0000000; // Blue color

// ... other code is skipped for brevity %>


3. Don't use such numbers. Sometimes we can use constants. For example Graphics Processor contains a lot of color constants which are more readable and convenient to use. You can read about using Graphics Processor constants here. Here is a code sample:

Code:
[JScript]
<!-- METADATA TYPE="typelib" UUID="{9AAC3E0E-8B1D-4D3A-9EF9-465BA8D31B12}"-->
<%
var oDrawingTool;
oDrawingTool = Server.CreateObject("GraphicsProcessor2002.DrawingTool");
oDrawingTool.DefaultPen.Color = gpBlue; // Blue color

// ... other code is skipped for brevity %>


Best regards,
Fedor Skvortsov
Users browsing this topic
Guest


Forum Jump
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.

Main Forum RSS : RSS

YAFVision Theme Created by Jaben Cargman (Tiny Gecko)
Yet Another Forum.net version 1.9.1.6 running under Cuyahoga.
Copyright © 2003-2006 Yet Another Forum.net. All rights reserved.