Visual Basic Concepts

Converting Scales

Use the ScaleX and ScaleY methods to convert from one scale mode to another scale mode. Those methods have the following syntax:

[object.]ScaleX(value[,fromScale[,toScale]]

[object.]ScaleY(value[,fromScale[,toScale]]

The destination object is a form, picture box, or Printer object. The value is expressed in the coordinate system specified by the scale mode fromScale. The value returned is expressed in the scale mode specified by toScale, or the scale mode of object if toScale is omitted. If fromScale is omitted, the scale mode for value is HIMETRIC.

HIMETRIC is the scale mode that specifies physical sizes. For example, the number of HIMETRIC units in a line of 10 centimeters is 10,000. The resulting line drawn on the screen is ten centimeters long, regardless of the size of the video display area. For information on the HIMETRIC scale mode and physical sizes, see the Microsoft Windows SDK.

The following statement stretches the content of the picture box control MyPic to twice its width. MyPic.Picture.Width returns the width of the picture contained in the picture control, which is a HIMETRIC value that needs to be converted into the scale mode of Form1.

Form1.PaintPicture MyPic.Picture, X, Y, _
   Form1.ScaleX(MyPic.Picture.Width) * 2

The following example illustrates two equivalent ways to specify a form’s Width to np pixels wide.

' The ScaleMode of the form is set to pixels.
ScaleMode = vbPixels

' Option 1:
' Temporarily set the form’s ScaleMode to twips.
ScaleMode = vbTwips
' ScaleX() returns the value in twips.
Width = Width - ScaleWidth + ScaleX(np, vbPixels)
' Set back the ScaleMode of the form to pixels.
ScaleMode = vbPixels
' Option 2:
' Conversion from pixels to twips without changing
'    the ScaleMode of the form.
Width = Width + ScaleX(np - ScaleWidth, vbPixels, _
   vbTwips)

*For More Information* See "ScaleX Property" or "ScaleY Property" in the Language Reference.