Results 1 to 7 of 7

Thread: limiting the decimal point to 1

Hybrid View

  1. #1
    PowerPoster RhinoBull's Avatar
    Join Date
    Mar 2004
    Location
    New Amsterdam
    Posts
    24,132

    Re: limiting the decimal point to 1

    Here is another approach - it's not perfect (just a quick sample) so you may need to work with code written in the Text1_Change() evnt handler:
    VB Code:
    1. Option Explicit
    2.  
    3. Private Const GWL_STYLE = (-16)
    4. Private Const ES_NUMBER = &H2000&
    5.  
    6. Private Declare Function GetWindowLong _
    7.     Lib "user32" Alias "GetWindowLongA" _
    8.     (ByVal hwnd As Long, ByVal nIndex As Long) As Long
    9.  
    10. Private Declare Function SetWindowLong _
    11.     Lib "user32" Alias "SetWindowLongA" _
    12.     (ByVal hwnd As Long, ByVal nIndex As Long, _
    13.     ByVal dwNewLong As Long) As Long
    14.  
    15. Private Sub Form_Load()
    16. '========================
    17. Dim curStyle&, newStyle&
    18.  
    19.     'allow numeric entries only
    20.     Text1.Text = ""
    21.     curStyle = GetWindowLong(Text1.hwnd, GWL_STYLE) Or ES_NUMBER
    22.     newStyle = SetWindowLong(Text1.hwnd, GWL_STYLE, curStyle)
    23.    
    24. End Sub
    25.  
    26. Private Sub Text1_Change()
    27.     If IsNumeric(Text1.Text) Then
    28.         Text1.Text = Format(Text1.Text, "0.0")
    29.     End If
    30. End Sub

  2. #2

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