OnlyNumbers (2)




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

'Functions


Public Const GWL_STYLE = (-16)
Public Const ES_NUMBER = &H2000&

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 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

Questo e' un modo per impedire ad un utente di introdurre lettere
in una test box. Questo metodo setta il window style della text
box, impedendole di accettare lettere. E' possibile usare un
altro metodo usando l'evento KeyPress della text box,
intercettando le lettere, ma questo metodo non necessita di
codice nell'evento della text box.










( onlynumbers2.html )- by Paolo Puglisi - Modifica del 17/12/2023