Results 1 to 3 of 3

Thread: for Currency or with Decimal Point

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Mar 2001
    Posts
    82

    for Currency or with Decimal Point

    I was able to get API codes in this site on how to set the text box to accept numerical inputs only, but unfortunately it also disallows the user to input a decimal point or period. What modifications do I need to make to allow the user to input the decimal point?

    Here is the code that I got:

    Private Declare Function GetWindowLong& Lib "user32" Alias "GetWindowLongA" (ByVal hWnd As Long, ByVal nIndex As Long)
    Private Declare Function SetWindowLong& Lib "user32" Alias "SetWindowLongA" (ByVal hWnd As Long, ByVal nIndex As Long, ByVal dNewLong As Long)
    Private Const ES_NUMBER = &H2000&
    Private Const GWL_STYLE = (-16)

    Public Sub makeNumeric(ByRef refTextBox As TextBox)
    'makes the textbox numeric only
    Dim tmpValue&
    Dim fAlignment&
    Dim ret&
    fAlignment& = ES_NUMBER
    tmpValue& = GetWindowLong&(refTextBox.hWnd, GWL_STYLE)
    ret& = SetWindowLong&(refTextBox.hWnd, GWL_STYLE, tmpValue& Or fAlignment&)
    refTextBox.Refresh
    End Sub

    Thank you.

  2. #2
    Matthew Gates
    Guest
    You don't really need API to do this.

    Try this instead:


    VB Code:
    1. Private Sub Text1_KeyPress(KeyAscii As Integer)
    2.     If KeyAscii < 33 Or KeyAscii = Asc(".") Then Exit Sub
    3.     If Not (IsNumeric(Chr(KeyAscii))) Then KeyAscii = 0
    4. End Sub

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Mar 2001
    Posts
    82

    Appreciated

    Thank you. I never thought of that. Thanks.

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