DescriptionSometimes 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 %>
ReasonThe 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.
SolutionUnfortunately 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