Textbox

Discussion in 'Questions (Windows Mobile)' started by kavka, Mar 12, 2008.

  1. kavka

    kavka Member Licensed User

    Hello!

    Is it possible to define a textbox, that it will not accept fonts and will accept only numbers? Any ideas?

    Thx, Kavka
     
  2. Hennell

    Hennell Member Licensed User

    Doubt this is the best way but:

    Code:
    Sub TextBox1_KeyPress (key)
       
    For i = 48 To 57
        
    If key = Chr(i) Then Return
       
    Next
    textbox1.IgnoreKey
       
    End Sub
    would make a text box only accept numbers.
     
  3. agraham

    agraham Expert Licensed User

    Right idea but better coded as
    Code:
    Sub TextBox1_KeyPress (key)
      
    If (Asc(key) < 48 OR Asc(key) > 59AND Asc(key) <> 8 Then
      
    ' allow 0 to 9 and backspace keys
      textbox1.IgnoreKey
      
    End If
    End Sub
     
  4. Hennell

    Hennell Member Licensed User

    Huh - I was closer then I thought I'd be. Although forgetting backspace was a daft oversight...
     
  5. specci48

    specci48 Well-Known Member Licensed User

    Last edited: Mar 12, 2008
  6. Erel

    Erel Administrator Staff Member Licensed User

    Small modification:
    Code:
    Sub TextBox1_KeyPress (key)
      
    If Not(IsDigit(key)) AND Asc(key) <> 8 Then
      
    ' allow 0 to 9 and backspace keys
          textbox1.IgnoreKey
      
    End If
    End Sub
     
  7. alfcen

    alfcen Well-Known Member Licensed User

    Splitting hairs, for decimal numbers in both English (.) and Continental (,)notations as well as allowing for negative numbers:

    Code:
    If (Asc(key) < 44 OR Asc(key) > 59AND Asc(key) <> 8 Then txtZT.IgnoreKey
    The included slash, Chr(48), is a compromise for a shorter line of code.
     
  8. dennishea

    dennishea Active Member Licensed User

    Their are many ways to skin a kitty but team work makes for the most effiecent way. :sign0188:

    p.s. I think that this is a ten star forum.
     
  9. kavka

    kavka Member Licensed User

    Hello!

    Erel, used your code with small modification you made and works great!

    Thx, Kavka
     
Loading...
  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