Overflow Error Plotting Points Far Outside Bounds of ControlLast reviewed: June 21, 1995Article ID: Q81953 |
|
The information in this article applies to:
- Standard and Professional Editions of Microsoft Visual Basic for Windows, versions 2.0 and 3.0- Microsoft Visual Basic programming system for Windows, version 1.0
SUMMARYVisual Basic for Windows may give an Overflow error when you plot points on a form or picture box if a point's coordinates far exceed the borders and scale of the form or control. The point at which overflow occurs depends on the ScaleMode property value and the points plotted. In the case of ScaleMode = 0 (User Defined Scale), the size of the form or picture box and the scale chosen are also determinants. A workaround is to trap the error and use a RESUME NEXT statement to exit the error handler. The example below contains the necessary code to trap the Overflow error.
MORE INFORMATIONBefore Visual Basic for Windows can plot a point, it must first convert the coordinates into their absolute location in twips. If, after the conversion, one or both coordinates are greater than 32,767 or less than -32,768, an Overflow error is generated. The following chart lists the ScaleModes, their equivalence in twips, and the values that will cause a coordinate (z) to overflow:
Equivalents ScaleMode in Twips (Tp) Overflow Point (z)
0 (User defined) User defined User defined (see example)
1 (Twips) 1 twip = 1 twip (z < -32768) or (z > 32767)
2 (Point) 1 point = 20 twips (z < -1638) or (z > 1638)
3 (Pixel) System dependent System dependent
4 (Character) x-axis=120 twips/char (x < -273) or (x > 273)
y-axis=240 twips/char (y < -136) or (y > 136)
5 (Inch) 1 Inch = 1440 twips (z < -22) or (z > 22)
6 (Millimeter) 1 mm = 56.7 twips (z < -577) or (z > 577)
7 (Centimeter) 1 cm = 567 twips (z < -57) or (z > 57)
The example below can be used to determine the value that generates
the Overflow error for ScaleMode 0 or 3.
Example1. Run Visual Basic for Windows, or from the File menu, choose NewProject (press ALT, F, N) if Visual Basic for Windows is already running. Form1 is created by default.
Control Name (use CtlName in Visual Basic 1.0 for Windows) --------------------------------------------------------------------- Text box Text1 Command button Command1
Sub Form_Load ()
Command1.Caption = "Find Ranges"
'* Change ScaleMode to see different results.
Form1.ScaleMode = 3 ' PIXEL.
End Sub
Sub Command1_Click ()
CR$ = Chr$(13) + Chr$(10) ' Carriage return.
X = FindValue("X")
Y = FindValue("Y")
Text1.Text = "Valid value when..."
Text1.Text = Text1.Text + CR$ + "-" + Str$(X) + " < X < " + Str$(X)
Text1.Text = Text1.Text + CR$ + "-" + Str$(Y) + " < Y < " + Str$(Y)
End Sub
Function FindValue (Which$) On Error GoTo rlhandler
HiValue = 100000
LoValue = 0
Errored = FALSE
' Do binary select.
Do
NewCheck = Value
If Errored Then
Value = HiValue - (HiValue - LoValue) \ 2
Else
Value = LoValue + (HiValue - LoValue) \ 2
End If
If Which$ = "X" Then
Form1.PSet (Value, 0)
Else
Form1.PSet (0, Value)
End If
If ErrorNum = 6 Then
HiValue = Value
ErrorNum = 0
Else
LoValue = Value
End If
Loop Until NewCheck = Value
FindValue = Value
Exit Function
rlhandler:
' Err = 6 is OverFlow error.
If Err = 6 Then
ErrorNum = Err
Else
Form1.Print Err
End If
Resume Next
End Function
|
Additional reference words: 1.00 2.00 3.00
© 1998 Microsoft Corporation. All rights reserved. Terms of Use. |