none
How to update a 2nd. TextBox with every keyclick? RRS feed

  • Question

  • My Excel AddIn creates a number of tabs (spreadsheets) as instructed by the user. See screenshot:

    The TextBox on top is filled by the user while the bottom ones (read only) are filled programmatically. The contents of the bottom left TextBox is constant and easy to determine, my code places n+1 in that field (where n = No. of tabs). The tricky part is to update the bottom right TextBox as the user types. I have considered two possibilities:

    (1) As the user types a number, the "Ok" button is disabled. As soon as s/he is finished typing she clicks on the empty space (or perhaps with a [Tab] key exits the field), signaling that the input number is ready and that click event enables the "Ok" button. The user would have to click twice, then.

    (2) This option is the one in the subject line. As the user types, all non-digit characters are ignored and the bottom right TextBox is updated with each keyclick event that contains a digit.

    I am somewhat familiar with WPF coding, know very little about Windows Forms. Detailed instructions are most appreciated.

    TIA

    Wednesday, May 16, 2018 11:53 PM

Answers

  • The solution is here:

        https://stackoverflow.com/questions/50430986/how-to-constrain-keyclicks-to-digits-only-before-they-are-seen-in-a-windows-fom

    I appreciate the help from VBA programmers, but next time I will make sure to inform the readers that I program exclusively in C#.

    Thanks to all!

    Wednesday, May 30, 2018 2:12 PM

All replies

  • Not sure what the extra boxes "tabs 1 to X will be added" are for when what's above is already perfectly clear.

    What you might want to do though is validate what the user enters in the textbox is numeric, and update the textbox, (dis)enable the OK button, and if you still think you need it, the extra label. You could adapt the following

    Private mCntTabs As Long
    
    Private Sub TextBox1_Change()
        If Len(TextBox1.Text) = 0 Then
        mCntTabs = 0
        ElseIf CStr(Val(TextBox1.Text)) = TextBox1.Text Then
            mCntTabs = Val(TextBox1.Text)
        Else
            TextBox1 = IIf(mCntTabs, mCntTabs, "")
        End If
    
        cmdOK.Enabled = mCntTabs ' dis/enable the OK button
        LabelTo = TextBox1  ' update the tabs will be added label
    End Sub

    If the dialog form is to remain after clicking OK or Cancel, reset the textbox to "" and nCntTabs to zero. At design or when the form loads disable the OK button

    Instead of a textbox, a combobox or listbox populated with numbers would be alternatives

    Thursday, May 17, 2018 8:47 AM
    Moderator
  • Not sure what the extra boxes "tabs 1 to X will be added" are for when what's above is already perfectly clear.

    It is clear for you and all the readers. Suffice to say that some of the users of my apps are complete newbies and are overworked, prone to mistakes. That is an extra measure of foolproofness (*). These people are on a daily basis doing repetitive, mind numbing work. Today they have to add say, 100 tabs manually. The turnaround is enormous, they keep on resigning. We are making a big effort to make their work more humane, automated.

    The quoted comment illustrates a problem that I constantly find among my esteemed colleagues: We tend to assume that "the whole world is like me". Due respect.

    Thanks

    (*) Somebody said/wrote:

    "The problem with writing foolproof software is that fools are too clever."  : -)










    Thursday, May 17, 2018 12:17 PM
  • Not sure what the extra boxes "tabs 1 to X will be added" are for when what's above is already perfectly clear.

    It takes my users days, or more to fill the huge spreadsheets and some are "a work in progress". If the data entry in a workbook was already started days before, the dialog will say: "Tabs No. 33 to 57 will be added", and the number 57 should match the XML file that the engineers send to my users (otherwise, they are inserting the data in the wrong file). A few days, later, it may say "Tabs 58 to 64 will be added", again it must match. Despite my instinctive inclinations to make the code more general, the most experienced user and myself agreed that the app should not accept gaps or overlaps. Maybe overlaps (removing/replacing spreadsheets) in the future, hence the read only fields. All three may become editable, users edit any two, while the 3rd. keeps sanity.

    Thanks again (and thanks for keeping me honest  : -)





    Thursday, May 17, 2018 12:25 PM
  • Fair enough.
    Did you try my example, I think it should be easy to adapt to what you're looking for?
    Thursday, May 17, 2018 3:14 PM
    Moderator
  • Fair enough.
    Did you try my example, I think it should be easy to adapt to what you're looking for?

    That is my next step.

    Thx

    Thursday, May 17, 2018 5:34 PM
  • Hi Travis,

    Do you have any issue with this thread?

    If not, I would suggest you mark the helpful reply as answer which is the way to close a thread.

    If you do, please feel free to let us know, we will try to provide further suggestion.

    Best Regards,

    Tao Zhou


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Wednesday, May 30, 2018 12:26 PM
  • The solution is here:

        https://stackoverflow.com/questions/50430986/how-to-constrain-keyclicks-to-digits-only-before-they-are-seen-in-a-windows-fom

    I appreciate the help from VBA programmers, but next time I will make sure to inform the readers that I program exclusively in C#.

    Thanks to all!

    Wednesday, May 30, 2018 2:12 PM
  • Hi Travis,

    Thanks for sharing the solution.

    I would suggest you mark your reply as answer, and then others who run into the same issue would find the solution easily.

    Best Regards,

    Tao Zhou


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Thursday, May 31, 2018 7:22 AM
  • That is an excellent idea, Tao.

    Done

    Thursday, May 31, 2018 9:37 AM