Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

numeric up down control in vba

Is there an in-built numeric updown control in vba or do we need to create a control like that?

If there is such a control then what are the events that we may use.

Pls suggest.

like image 701
Premanshu Avatar asked Jun 20 '12 09:06

Premanshu


People also ask

What is numeric updown in VB net?

The Windows Forms NumericUpDown control looks like a combination of a text box and a pair of arrows that the user can click to adjust a value. The control displays and sets a single numeric value from a list of choices.

What is the property that determines by how much the current number In a NumericUpDown control changes when the user clicks the up ARROW or the down ARROW?

The Increment property sets the amount that the number is adjusted by when the user clicks an up or down arrow.

What is NumericUpDown control In c#?

A NumericUpDown control contains a single numeric value that can be incremented or decremented by clicking the up or down buttons of the control. The user can also enter in a value, unless the ReadOnly property is set to true .


1 Answers

You can use the SpinButton1 control for that

SNAPSHOT

enter image description here

CODE

You can either set the min and max of the SpinButton1 in design time or at runtime as shown below.

Private Sub UserForm_Initialize()
    SpinButton1.Min = 0
    SpinButton1.Max = 100
End Sub

Private Sub SpinButton1_Change()
    TextBox1.Text = SpinButton1.Value
End Sub

FOLLOWUP

If you want to increase or decrease the value of the textbox based on what user has input in the textbox then use this. This also makes the textbox a "Number Only" textbox which just fulfills your other request ;)

Private Sub SpinButton1_SpinDown()
    TextBox1.Text = Val(TextBox1.Text) - 1
End Sub

Private Sub SpinButton1_SpinUp()
    TextBox1.Text = Val(TextBox1.Text) + 1
End Sub

Private Sub TextBox1_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger)
    Select Case KeyAscii
      Case vbKey0 To vbKey9, 8
      Case Else
        KeyAscii = 0
        Beep
    End Select
End Sub
like image 101
Siddharth Rout Avatar answered Sep 23 '22 20:09

Siddharth Rout