Results 1 to 7 of 7

Thread: ascii

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Oct 2000
    Posts
    77

    Unhappy

    i have one textbox how would i make that textbox that user can't type other then number not word's also spacebar and backspace work but user can't type just alphabatic word. does any one know how to do this

  2. #2
    Hyperactive Member scuzymoto's Avatar
    Join Date
    Aug 1999
    Location
    Washington State
    Posts
    316
    Don't use a text box. Used a MaskedEdit Box. You can then put in the mask property something like this... ##### and it will only allow the user to enter numbers. The maskededit control is in your components list.
    SCUZ

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Oct 2000
    Posts
    77

    thank you

    thank you but i knew about makededit but i don't want that i want to lurn with textbox becaue i am beganner, but thanks

  4. #4
    Hyperactive Member scuzymoto's Avatar
    Join Date
    Aug 1999
    Location
    Washington State
    Posts
    316
    Use the keydown event to check what they have typed and then put in code to block it. Their is a parameter in the keydown event that tells you what key is being pressed and then a value to let you cancel the key. Ill put up some code if you want.
    SCUZ

  5. #5
    Fanatic Member Mad Compie's Avatar
    Join Date
    Aug 2000
    Location
    Kuurne (Belgium)
    Posts
    553
    You have funny names, are you Japanese?
    Just kidding, here's a shorter way, using 2 API functions:
    Code:
    'This project needs a TextBox
    Private Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long) As Long
    Private Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
    Const GWL_STYLE = (-16)
    Const ES_NUMBER = &H2000&
    Public Sub SetNumber(NumberText As TextBox, Flag As Boolean)
        Dim curstyle As Long, newstyle As Long
    
        'retrieve the window style
        curstyle = GetWindowLong(NumberText.hwnd, GWL_STYLE)
    
        If (Flag) Then
           curstyle = curstyle Or ES_NUMBER
        Else
           curstyle = curstyle And (Not ES_NUMBER)
        End If
    
        'Set the new style
        newstyle = SetWindowLong(NumberText.hwnd, GWL_STYLE, curstyle)
        'refresh
        NumberText.Refresh
    End Sub
    Private Sub Form_Load()
        SetNumber Text1, True
        Me.Caption = "Now, try typing some letters into the textbox"
    End Sub

  6. #6
    Guest
    Insert the following code in your TextBox. It will filter out A-z.
    Code:
    Private Sub Text1_KeyPress(KeyAscii As Integer)
        If Chr(KeyAscii) Like "[A-z]" Then KeyAscii = 0
    End Sub

  7. #7
    Fanatic Member ExcalibursZone's Avatar
    Join Date
    Feb 2000
    Location
    Western NY State
    Posts
    908
    Code:
    'Check for a Numeric Character, Excluding Backspace and Space. Verified with VB6.
    Private Sub Text1_KeyPress(KeyAscii As Integer)
        If Not(IsNumeric(Chr(KeyAscii))) And KeyAscii <> 32 And KeyAscii <> 8 Then KeyAscii = 0
    End Sub
    -Excalibur

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