none
How to manage a SpinButton in VBA RRS feed

  • Question

  • Hello,

    What are the important properties of a SpinButton so that the program will be able to capture the selected value?

    Thanks

    Monday, October 3, 2016 8:37 AM

Answers

  • Hi,

    here a (draft) sample.

    Module:

    Public spinBox() As String             'Array to hold values
    Public spinBoxIdx As Integer           'Index pointer for Array
    Public MyResult As String
    Sub Test()
    UserForm1.Show
    MsgBox MyResult
    End Sub

    Form, with SpinButton1, CommandButton1, TextBox1:

    Private Sub CommandButton1_Click()
    MyResult = TextBox1.Text
    Unload UserForm1
    End Sub
    
    Private Sub UserForm_Initialize()
    'Set Index Pointer & Load Array
    ReDim spinBox(SpinButton1.Max - SpinButton1.Min)
    
    For spinBoxIdx = 0 To SpinButton1.Max - SpinButton1.Min
        spinBox(spinBoxIdx) = "Text " & SpinButton1.Min + spinBoxIdx
    Next spinBoxIdx
    spinBoxIdx = 0
    TextBox1.Text = spinBox(spinBoxIdx)
    End Sub
    Private Sub SpinButton1_SpinDown()
    'Test to see if we're already at the end of the array
    If spinBoxIdx = SpinButton1.Max - SpinButton1.Min Then
        'If so, leave the index pointer
        spinBoxIdx = spinBoxIdx
    Else    'If Not
        'adjust the index pointer
        spinBoxIdx = spinBoxIdx + 1
    End If
    'Update the TextBox
    TextBox1.Text = spinBox(spinBoxIdx)
    End Sub
    Private Sub SpinButton1_SpinUp()
    'Test to see if we're already at the end of the array
    If spinBoxIdx = 0 Then
        'If so, leave the index pointer
        spinBoxIdx = spinBoxIdx
    Else    'If Not
        'adjust the index pointer
        spinBoxIdx = spinBoxIdx - 1
    End If
    'Update the TextBox
    TextBox1.Text = spinBox(spinBoxIdx)
    End Sub
    

    Does that help?
    Regards
    Barbara


    To increase the value of this forum, please mark the replies that helped to solve your issue as answer. If you find answers to questions from other forum participants to be helpful, please mark them as helpful. Your participation will help others to find an appropriate solution faster. Thanks for your support!

    • Marked as answer by WLID1966 Tuesday, October 4, 2016 4:03 PM
    Tuesday, October 4, 2016 1:52 PM
    Moderator

All replies

  • Hi,

    here a (draft) sample.

    Module:

    Public spinBox() As String             'Array to hold values
    Public spinBoxIdx As Integer           'Index pointer for Array
    Public MyResult As String
    Sub Test()
    UserForm1.Show
    MsgBox MyResult
    End Sub

    Form, with SpinButton1, CommandButton1, TextBox1:

    Private Sub CommandButton1_Click()
    MyResult = TextBox1.Text
    Unload UserForm1
    End Sub
    
    Private Sub UserForm_Initialize()
    'Set Index Pointer & Load Array
    ReDim spinBox(SpinButton1.Max - SpinButton1.Min)
    
    For spinBoxIdx = 0 To SpinButton1.Max - SpinButton1.Min
        spinBox(spinBoxIdx) = "Text " & SpinButton1.Min + spinBoxIdx
    Next spinBoxIdx
    spinBoxIdx = 0
    TextBox1.Text = spinBox(spinBoxIdx)
    End Sub
    Private Sub SpinButton1_SpinDown()
    'Test to see if we're already at the end of the array
    If spinBoxIdx = SpinButton1.Max - SpinButton1.Min Then
        'If so, leave the index pointer
        spinBoxIdx = spinBoxIdx
    Else    'If Not
        'adjust the index pointer
        spinBoxIdx = spinBoxIdx + 1
    End If
    'Update the TextBox
    TextBox1.Text = spinBox(spinBoxIdx)
    End Sub
    Private Sub SpinButton1_SpinUp()
    'Test to see if we're already at the end of the array
    If spinBoxIdx = 0 Then
        'If so, leave the index pointer
        spinBoxIdx = spinBoxIdx
    Else    'If Not
        'adjust the index pointer
        spinBoxIdx = spinBoxIdx - 1
    End If
    'Update the TextBox
    TextBox1.Text = spinBox(spinBoxIdx)
    End Sub
    

    Does that help?
    Regards
    Barbara


    To increase the value of this forum, please mark the replies that helped to solve your issue as answer. If you find answers to questions from other forum participants to be helpful, please mark them as helpful. Your participation will help others to find an appropriate solution faster. Thanks for your support!

    • Marked as answer by WLID1966 Tuesday, October 4, 2016 4:03 PM
    Tuesday, October 4, 2016 1:52 PM
    Moderator
  • Great!

    Thanks

    Tuesday, October 4, 2016 4:03 PM