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:
Option Explicit Private Const GWL_STYLE = (-16) Private Const ES_NUMBER = &H2000& 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 Private Sub Form_Load() '======================== Dim curStyle&, newStyle& 'allow numeric entries only Text1.Text = "" curStyle = GetWindowLong(Text1.hwnd, GWL_STYLE) Or ES_NUMBER newStyle = SetWindowLong(Text1.hwnd, GWL_STYLE, curStyle) End Sub Private Sub Text1_Change() If IsNumeric(Text1.Text) Then Text1.Text = Format(Text1.Text, "0.0") End If End Sub




Reply With Quote