Visual Basic Reference
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