Limiting Text Entry Length

Discussion in 'Questions (Windows Mobile)' started by jireland, Jan 8, 2008.

  1. jireland

    jireland Member Licensed User

    Is there a way of limiting the length of text entry?
    I want the User to enter a single charachter in a text box of only one character wide. I have tried the TextBox.Selection length, but without success.
    I must be doing something wrong, but not sure what.....
  2. Erel

    Erel Administrator Staff Member Licensed User

    You can use the KeyPress event:
    Sub TextBox1_KeyPress (key)
    If StrLength(TextBox1.Text) >= 1 AND Asc(key) <> 8 Then TextBox1.IgnoreKey
    End Sub
    Asc(key) <> 8 - Always allow the BackSpace key.

    You can also use agrham's ControlEvents library and catch the TextChanged event.
    Inside this event check the length of TextBox.Text and trim it if necessary.
  3. jireland

    jireland Member Licensed User


    Thanks for the quick response, I'll give it a whirl.

    Much appreciated.
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice