Welcome Guest! You need to login or register to make posts.

Notification

Icon
Error

Options
Go to last post Go to first unread
Fedor  
#1 Posted : Sunday, September 29, 2002 10:28:00 PM(UTC)
Fedor

Rank: Advanced Member

Groups: Member, Administration, Moderator
Joined: 7/28/2003(UTC)
Posts: 1,572

Thanks: 5 times
Was thanked: 64 time(s) in 63 post(s)
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. Here is a code sample how to use Graphics Processor constants:

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 %>

Edited by user Wednesday, October 29, 2008 2:14:55 PM(UTC)  | Reason: Not specified

Best regards,
Fedor Skvortsov
Users browsing this topic
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.