VBA/Excel/Access/Word/Forms/SpinButton

Материал из VB Эксперт
Перейти к: навигация, поиск

Assign value from a TextBox to a Spinner

   <source lang="vb">

 Private Sub TextBox1_Change()
     Dim NewVal As Integer
     NewVal = Val(TextBox1.Text)
     If NewVal >= SpinButton1.Min And _
         NewVal <= SpinButton1.Max Then _
         SpinButton1.Value = NewVal
 End Sub
</source>
   
  


Set Spinner value to a TextBox

   <source lang="vb">

 Private Sub SpinButton1_Change()
     TextBox1.Text = SpinButton1.Value
 End Sub
</source>
   
  


Set the SpinButton Min/Max and current value

   <source lang="vb">

Private Sub UserForm_Initialize()

   With SpinButton1
       .Min = 1
       .Max = 100
       Label1.Caption = "Specify a value between " & .Min & " and " & .Max & ":"

" Initialize Spinner

       .Value = 1

" Initialize TextBox

       TextBox1.Text = .Value
   End With

End Sub

</source>
   
  


Spin up event procedure for spin button

   <source lang="vb">

    Private Sub SpinButton1_SpinUp()
        With Range("B4")
            "Increase value in B4 by .05%. Stop at 1%
            .Value = WorksheetFunction.Min(0.01, .Value + 0.0005)
        End With
    End Sub
</source>
   
  


The spin button control uses the SpinDown and SpinUp events to decrease and increase the value in cell B4

   <source lang="vb">

"Spin down event procedure for spin button

    Private Sub SpinButton1_SpinDown()
        With Range("B4")
            "Decrease value in B4 by .05%. Stop at 0%
            .Value = WorksheetFunction.Max(0, .Value - 0.0005)
        End With
    End Sub
</source>