CST2601 Visual Basic I
Notes on Scale


Scale Method

Defines the coordinate system for a Form, PictureBox, or Printer. Doesn't support named arguments.

Syntax

object.Scale (x1, y1) - (x2, y2)

The Scale method syntax has these parts:

Part Description
object Optional. An object expression that evaluates to an object in the Applies To list. If object is omitted, the Form object with the focus is assumed to be object.
x1, y1 Optional. Single-precision values indicating the horizontal (x-axis) and vertical (y-axis) coordinates that define the upper-left corner of object. Parentheses must enclose the values. If omitted, the second set of coordinates must also be omitted.
x2, y2 Optional. Single-precision values indicating the horizontal and vertical coordinates that define the lower-right corner of object. Parentheses must enclose the values. If omitted, the first set of coordinates must also be omitted.
 

Remarks

The Scale method enables you to reset the coordinate system to any scale you choose. Scale affects the coordinate system for both run-time graphics statements and the placement of controls.

If you use Scale with no arguments (both sets of coordinates omitted), it resets the coordinate system to twips.

Scale Method Example

This example uses the Scale method to set up a custom coordinate system so that a bar chart can be drawn on a form. To try this example, paste the code into the Declarations section of a form, and then press F5 and click the form.

Private Sub Form_Click ()
   Dim I, OldFontSize   ' Declare variables.
   Width = 8640: Height = 5760   ' Set form size in twips.
   Move 100,100   ' Move form origin.
   AutoRedraw = -1   ' Turn on AutoRedraw.
   OldFontSize = FontSize   ' Save old font size.
   BackColor = QBColor(7)   ' Set background to gray.
   Scale (0, 110)-(130, 0)   ' Set custom coordinate system.
   For I = 100 To 10 Step -10
      Line (0, I)-(2, I)   ' Draw scale marks every 10 units.
      CurrentY = CurrentY + 1.5   ' Move cursor position.
      Print I   ' Print scale mark value on left.
      Line (ScaleWidth - 2, I)-(ScaleWidth, I)
      CurrentY = CurrentY + 1.5   ' Move cursor position.
      CurrentX = ScaleWidth - 9
      Print I   ' Print scale mark value on right.
   Next I
   ' Draw bar chart.
   Line (10, 0)-(20, 45), RGB(0, 0, 255), BF   ' First blue bar.
   Line (20, 0)-(30, 55), RGB(255, 0, 0), BF   ' First red bar.
   Line (40, 0)-(50, 40), RGB(0, 0, 255), BF
   Line (50, 0)-(60, 25), RGB(255, 0, 0), BF
   Line (70, 0)-(80, 35), RGB(0, 0, 255), BF
   Line (80, 0)-(90, 60), RGB(255, 0, 0), BF
   Line (100, 0)-(110, 75), RGB(0, 0, 255), BF
   Line (110, 0)-(120, 90), RGB(255, 0, 0), BF
   CurrentX = 18: CurrentY = 100   ' Move cursor position.
   FontSize = 14   ' Enlarge font for title.
   Print "Widget Quarterly Sales"   ' Print title.
   FontSize = OldFontSize   ' Restore font size.
   CurrentX = 27: CurrentY = 93   ' Move cursor position.
   Print "Planned Vs. Actual"   ' Print subtitle.
   Line (29, 86)-(34, 88), RGB(0, 0, 255), BF   ' Print legend.
   Line (43, 86)-(49, 88), RGB(255, 0, 0), BF
End Sub