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:
    Code:
    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.
    http://www.basic4ppc.com/forum/showthread.php?t=934
     
  3. jireland

    jireland Member Licensed User

    Thanks!

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

    Much appreciated.
     
Loading...