+ Reply to Thread
Results 1 to 6 of 6

Custom TextBox Control

  1. #1
    Forum Expert
    Join Date
    03-31-2009
    Location
    Barstow, Ca
    MS-Off Ver
    Excel 2002 & 2007
    Posts
    2,164

    Custom TextBox Control

    I would like to create a Custom Control that I can then use in a form.
    I'm guessing that it would have to be a class like say clsTextBoxInteger.

    The class would have all the events that I always want in a TextBox control that restricts entry to Integers.

    I recognize that I can probably have the form's Initialize event create the objects from my class, but I can't see how it looks while I'm developing.

    Is there anyway to create the class and put it on the ToolBox so that I can just click on it to put it in the form, or maybe drag and drop it on my form?

    I'm considering creating my class and have it replace a TextBox during the form's initialze. That way I can see how it looks, but when I actually run the form the Textbox would be replaced by my clsTextBoxInteger.

    Are there any other options available to me?
    Foxguy

    Remember to mark your questions [Solved] and rate the answer(s)
    Forum Rules are Here

  2. #2
    Forum Expert snb's Avatar
    Join Date
    05-09-2010
    Location
    VBA
    MS-Off Ver
    Redhat
    Posts
    5,649

    Re: Custom TextBox Control

    or

    Please Login or Register  to view this content.
    or
    Please Login or Register  to view this content.



  3. #3
    Forum Expert
    Join Date
    03-31-2009
    Location
    Barstow, Ca
    MS-Off Ver
    Excel 2002 & 2007
    Posts
    2,164

    Re: Custom TextBox Control

    snb;

    I think you posted this answer to the wrong thread. If not, I have no idea what you're saying.

  4. #4
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,448

    Re: Custom TextBox Control

    I think snb is suggesting alternative ways to get the numeric input with out typeing the number.

    You can add the textboxes at design time and then assign them to a custom class in order to restrict numeric input only.

    class code CNumberBox
    Please Login or Register  to view this content.
    Userform code, add a single textbox to form
    Please Login or Register  to view this content.
    Cheers
    Andy
    www.andypope.info

  5. #5
    Forum Expert
    Join Date
    03-31-2009
    Location
    Barstow, Ca
    MS-Off Ver
    Excel 2002 & 2007
    Posts
    2,164

    Re: Custom TextBox Control

    Andy;

    I think that's what I'm looking for. I still can't see how it relates to snb's post. If it does I would like to see the connection.

    I do have one question before I test it.
    Please Login or Register  to view this content.
    Since you have "KeyAscii = vbNull", shouldn't it be "ByRef KeyAscii As MSForms.ReturnInteger"? What's the point of assigning vbNull if it can't be passed back to the calling Textbox?
    It just now occurred to me what the answer is. Textbox_KeyPress() is probably an event and VB looks for the exact words.
    But doesn't that make "KeyAscii = vbNull" pointless?

  6. #6
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    East Sussex, UK
    MS-Off Ver
    365, varying versions/builds
    Posts
    21,312

    Re: Custom TextBox Control

    The value passed is a pointer to the ReturnInteger object, so the ByVal refers to the object, not the value. It effectively works like ByRef therefore - much as the worksheet events that pass Target ByVal.
    Everyone who confuses correlation and causation ends up dead.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1