From CShellVB https://www.cshellvb.com
Change the style of a normal textbox so that it will only accept numbers. Better then evaluating keypress events and very fast. This call works on the fly and it is wrapped into a function for you.
Inputs
NumberText as Text Box and Flag as Boolean
Assumes
This changes the style of the textbox for the life of the form. Even if the form or textbox is refreshed the style will remain in effect!
Returns
None.
API Declarations'From CShellVB http://www.cshellvb.com
'Below is used for making a TextBox control accept
'only numbers. Very cool because it changes the style
'and does not require any code on the TextBox's events
'Place declares in Module
Declare Function GetWindowLong Lib "user32" _
Alias "GetWindowLongA" _
(ByVal hwnd As Long, ByVal nIndex As Long) As Long
Declare Function SetWindowLong Lib "user32" Alias _
"SetWindowLongA" _
(ByVal hwnd As Long, ByVal nIndex As Long, _
ByVal dwNewLong As Long) As Long
'Used for forcing only numbers in a textbox
Public Const GWL_STYLE = (-16)
Public Const ES_NUMBER = &H2000&