CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6

Thread: Updown Control

  1. #1
    Join Date
    Jun 1999
    Location
    Leicester England
    Posts
    61

    Updown Control

    Hi

    I am using a "UpDown" Control to increase/decrease the value of a text field, all seems to work correctly except a slight snag.

    I have declared a private variable for the form to hold the direction I wish to go (ie either "UP" or "DOWN").
    When the user presses the up arrow of the "UpDown" Control the UpClick() event sets the direction to "UP" and when he/she pressses the down arrow of the "UpDown" Control the DownClick() event sets the direction to "Down". I have written some code in the Change event of the "UpDown" Control that will either incerment or decrement the textbox value depending on my direction of travel but when I change directions I need to press the control twice before it goes in the right direction.

    In the help it says the change event is triggered before the UpClick() or DownClick() events - does anybody have ideas on how I can resolve this.

    Many thanks in advance.

    Raj



  2. #2
    Join Date
    Jan 2000
    Location
    CA
    Posts
    52

    Re: Updown Control

    There is an easier way to do this (without worrying about which direction the user is pressing)

    Assuming that you have a control UpDown1, and a text box Text1 on your form, this should work for you



    private Sub UpDown1_Change()
    Text1.Text = CStr(UpDown1.Value)
    End Sub





    Good Luck...


  3. #3
    Join Date
    Jun 1999
    Location
    Leicester England
    Posts
    61

    Re: Updown Control

    Hi
    Yes this works for incrementing normal integer values but my text box holds values in hh:mm:ss format and I have written some code that 1st increments the ss then the hh and then the mm. This is why I need to know the direction.

    Raj


  4. #4
    Join Date
    Sep 1999
    Location
    Red Wing, MN USA
    Posts
    312

    Re: Updown Control

    Put the code you have in the Change Event into your Own Sub, ie. Private Sub ChangeValue(ByVal bUp As Boolean) Then Call it from within the UPClick and DownClick Events, ie.

    private Sub UpDown1_UpClick()
    ChangeValue true
    End Sub

    private Sub UpDown1_DownClick()
    ChangeValue false
    End Sub

    private Sub ChangeValue(byval bUp as Boolen)
    If bUp then
    'Do Increment Code Here..
    else
    'Do Decrement Code Here..
    End If
    End Sub





    Aaron Young
    Analyst Programmer
    [email protected]
    [email protected]
    Aaron Young
    Senior Programmer Analyst (Red Wing Software)
    Certified AllExperts Expert

  5. #5
    Join Date
    Jun 1999
    Location
    Leicester England
    Posts
    61

    Re: Updown Control

    Hi
    Aaron - thanks for your code snippet this works ok but just for individual clicks only.
    I also need it to work when the user keeps any of the buttons pressed i.e. if the up button is pressed and held down the increment code is called until the user releases it and a similar case exists for the down button but here the decrement function is called until the user releases the down button.

    Raj


  6. #6
    Join Date
    Sep 1999
    Location
    Red Wing, MN USA
    Posts
    312

    Re: Updown Control

    Try this:

    private Sub UpDown1_Change()
    static lLast as Long
    static bUp as Boolean

    'Determine the Direction of the Change By Comparing the Current Value to the
    'Previous Value, If there's no Difference Must be Scrolling in the Same Direction as Before..
    If lLast < UpDown1 then
    bUp = true
    ElseIf lLast > UpDown1 then
    bUp = false
    End If
    lLast = UpDown1
    If bUp then
    'Do Incremental Code Here
    else
    'Do Decremental Code Here
    End If
    End Sub




    Aaron Young
    Analyst Programmer
    [email protected]
    [email protected]
    Aaron Young
    Senior Programmer Analyst (Red Wing Software)
    Certified AllExperts Expert

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured