A number of commercial programs have an
up-down box. This control is used when the user needs to enter a
numerical value. The up-down box gives users the option of typing
the number in directly or of clicking up or down buttons to
increase or decrease the value. You can create this functionality
in your VB6 programs by combining two of VB’s standard

Start by placing a TextBox control on your
form. Then, place a Vertical Scroll Bar right next to the TextBox.
Change the scroll bar control’s height to match that of the
TextBox. You want only the up and down buttons of the scroll bar to
be visible—the central part and thumb will be hidden. Then, set
scroll bar properties as follows:

  • Max: The lowest permitted
    value. This sounds counterintuitive but it’s the way scroll bars
    work, with the maximum value at the bottom of the bar.
  • Min: The largest permitted
  • SmallChange: The amount you
    want the value to change per click.
  • Value: The initial value
    you want in the text box.

Now put the following code in the form’s Load
event procedure to initialize the text box:

Text1.Text =

Finally, put the same code in the scroll bar
control’s Change event procedure to change the text box when the
user clicks the scroll bar’s up or down button:

Text1.Text = VScroll1.Value

Now you have a custom control that gives your
users a choice for entering numeric values.

Advance your scripting skills to the next level with TechRepublic’s free Visual Basic newsletter, delivered each Friday. Automatically sign up today!