You use this to only number can accept by a Textbox
1. Declare this API at You Declration Section (in your form/module):
-
'&& Only Allowing Number In Texttbox
-
Public Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hWnd As Long, ByVal nIndex As Long) As Long
-
-
Public Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hWnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
-
-
2. Create Private or Public sun in fom/module, use this code:
-
Public Sub SetNumber(NumberText As TextBox, Flag As Boolean)
-
Dim curstyle As Long
-
Dim newstyle As Long
-
-
curstyle = GetWindowLong(NumberText.hWnd, GWL_STYLE)
-
-
If Flag = True Then
-
curstyle = curstyle Or ES_NUMBER
-
Else
-
curstyle = curstyle And (Not ES_NUMBER)
-
End If
-
-
newstyle = SetWindowLong(NumberText.hWnd, GWL_STYLE, curstyle)
-
NumberText.Refresh
-
End Sub
-
3. And then you call that sun in any event, as example:
-
Public Sub Form_Load()
-
SetNumber textBox1, True
-
End Sub
-
Hope this work for you, i think it more simple than using a lot of loops..