Article ID: 100190 - Last Review: October 29, 2003 - Revision: 2.0 FIX: Overflow Error When CurrentX Or CurrentY Greater Than 32KThis article was previously published under Q100190 On This PageSYMPTOMS
An Overflow error results if you attempt to set CurrentX or CurrentY
to a value greater than 32,767 while the current ScaleMode is set to
Twips. When using another ScaleMode such as pixels, the same problem
occurs if the conversion of the CurrentX or CurrentY value to twips
is greater than 32,767. However, when you use the Print method (or other graphics method) you can correctly cause the value of CurrentX or CurrentY to exceed 32,767 when the ScaleMode is set to twips. CAUSE
When CurrentX or CurrentY is set explicitly, Visual Basic incorrectly
converts the value using the current scale mode to twips. If the result
of the conversion to twips is greater the 32,767, an Overflow error
occurs. For example, if the ScaleMode is set to Pixels, CurrentX and
CurrentY cannot exceed approximately 2731 pixels if the twips per pixel
ratio is 12 because 12 times 2731 is 32,772 which is greater than 32767. When setting CurrentX or CurrentY, Visual Basic should convert the value using the current ScaleMode to pixels rather than twips before comparing the result to 32,767. As a result of this bug, CurrentX and CurrentY are each restricted to a limit 12-14 times smaller (depending on TwipsPerPixelX or TwipsPerPixelY) than they should be. WORKAROUND
To work around the problem, call the Windows API functions:
STATUS
Microsoft has confirmed this to be a bug in the Microsoft products listed
at the beginning of this article. This problem has been fixed in Visual
Basic version 4.0.
MORE INFORMATION
Because the ratio of twips per pixel varies from one device (or screen
resolution) to another, you will need to calculate the limit for the device
you are using. To calculate the exact pixel limit of CurrentX, divide 32768
by Screen.TwipsPerPixelX. To calculate the limit of CurrentY, divide 32768
by Screen.TwipsPerPixelY. To find the limit of CurrentX and CurrentY for
your printer, use the Printer object in place of the Screen object in the
calculations above.
Example for Using API Calls as WorkaroundThe following example shows how to use the three API calls TextOut, MoveTo, and LineTo to work around the problem. Note that when you call Windows API functions to print or draw, all X and Y coordinates are measured in pixels regardless of the current ScaleMode setting.
APPLIES TO
| Article Translations
|

Back to the top
