| Make a new project. To the form add a text box and a command button. Code: Add this code to the form's General Declarations procedure: 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 Function SetNoNumbers(txt As TextBox, Flag As Boolean) Dim curstyle As Long Dim newstyle As Long curstyle = GetWindowLong(txt.hwnd, GWL_STYLE) If Flag Then curstyle = curstyle Or ES_NUMBER Else curstyle = curstyle And (Not ES_NUMBER) End If SetNoNums = SetWindowLong(txt.hwnd, GWL_STYLE, curstyle) txt.Refresh End Function Add this code to the command button: Private Sub Command1_Click() Call SetNoNumbers(Text1, True) End Sub |
Only allow numbers in a TextBox |
Freelance ASP PHP web development | Web developer India Web development India| Prayagasoft - web designer India, Ecommerce developer india, Ecommerce design