Results 1 to 4 of 4

Thread: [RESOLVED] Mask a TextBox in KeyPress Event

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Jan 2010
    Posts
    1,103

    Resolved [RESOLVED] Mask a TextBox in KeyPress Event

    I know the question is very basic. But it is important for validation for input via keyboard. And, it is not easy to consider all situation for ME.

    I have to consider Unicode,Control Keys, and Decimal Symbol/Digital Grouping Symbol Setting in Region/Language, and so on... I am headache.

    OK,let's go to topic:

    I have a TextBox1, I want 5 Masks, which is set up by an Enum:

    Code:
    Private Enum MaskEnum
      
        Numeric =0    'Allow  "-","." ,"," and Digit But After decimal symbol, only allow number of m_lDecimalLength
        Digital    =1   'Allow ONLY 0-9
        Letter    =2   'Allow All including Unicode
        Upper    =3   'ONLY allow Capital A-Z and 0-9 but you can input a-z by UCase conversion
        Lower   =4    'ONLY allow Capital a-z and 0-9 but you can input A-Z by LCase conversion
    
    End Enum
    Dim m_lDecimalLength As Long
    Dim m_eMask As MaskEnum
    Dim m_lMaxLength As Long 'Limit Max Length
    m_lDecimalLength = 2
    m_lMaxLength = 16 'If not set (=0). there's no limit
    Code:
    Private Text1_KeyPress(KeyAscii As Integer)
    
        Select Case m_eMask
             Case MaskEnum.Numeric 
                     '...
    
       End Select
    
    End Sub
    Last edited by Jonney; Jan 4th, 2015 at 07:16 PM.

  2. #2

    Thread Starter
    Frenzied Member
    Join Date
    Jan 2010
    Posts
    1,103

    Re: Mask a TextBox in KeyPress Event

    A little bit mess due to complicated check... Not sure I have considered all scenarios.

    Anyone has good neat codes for decimal input (allow "+","-",".","," and 0-9) validation considering number of Decimal and Max Length?
    Last edited by Jonney; Jan 5th, 2015 at 02:56 AM.

  3. #3
    gibra
    Guest

    Re: Mask a TextBox in KeyPress Event

    I suggest to use a Microsoft Masked Edit control (MSMASK32.OCX).

  4. #4

    Thread Starter
    Frenzied Member
    Join Date
    Jan 2010
    Posts
    1,103

    Re: Mask a TextBox in KeyPress Event

    Quote Originally Posted by gibra View Post
    I suggest to use a Microsoft Masked Edit control (MSMASK32.OCX).
    Masked Edit could be a solution.

    Right now ,my code works but a bit mess pending for clear up.
    So I can mark this thread resolved.

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