On The Insider: Sexy Aussie Babes

Create an up-down box for your VB6 programs

Tags: Microsoft development tools, Peter Aitken, Microsoft Visual Basic 6.0, scroll bar, up-down box, down button, TextBox, Visual Basic Tips Newsletter

  • Save
  • Print
  • 1

Takeaway: 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. See how you can create an up-down box in your VB6 programs by combining two of VB's standard controls.

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 controls.

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 value.
  • 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 = VScroll1.Value

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!

  • Save
  • Print
  • 1

Print/View all Posts Comments on this article

Not sure why you need to use a scrollbar,omnitech_1@...  | 12/05/05
Up-Down optionsaikimark@...  | 04/21/06
This is neater than entering into textbox directlyphilip29@...  | 04/21/06
Fractional valuesomnitech_1@...  | 04/23/06
Fractional Valuesmikey35@...  | 04/21/06

What do you think?

advertisement
Click Here