Results 1 to 3 of 3

Thread: accept only numerical values

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Jan 2001
    Location
    UK
    Posts
    205

    accept only numerical values

    How do you use the api to force text boxes to only accept numerical values. Also only numbers not decimal points etc. These numbers will be ints or longs but not float or double.

  2. #2
    Megatron
    Guest
    You need to add the ES_NUMBER style.
    Code:
    Private Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
    Private Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long) As Long
    Private Const ES_NUMBER = &H2000&
    Private Const GWL_STYLE = (-16)
    
    Private Sub Command1_Click()
        Dim lStyle As Long
        lStyle = GetWindowLong(Text1.hwnd, GWL_STYLE) Or ES_NUMBER
        SetWindowLong Text1.hwnd, GWL_STYLE, lStyle
    End Sub

  3. #3
    Megatron
    Guest
    Also, here's a non-API method, if you like:
    Code:
    Private Sub Text1_KeyPress(KeyAscii As Integer)
        If Not (Chr(KeyAscii) Like "#") Then KeyAscii = 0
    End Sub

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