OnlyNumbers



Function FiltraTasti(cContr As Control, iCodiceTasto _
As Integer, iMaxLen as Integer)
If iCodiceTasto = vbKeyBack Then
FiltraTasti = iCodiceTasto
Exit Function
End If
If Len(cContr.Text) >= iMaxlen Then
If cContr.SelLength = 0 Then
FiltraTasti = 0
Exit Function
End If
End If
If Not IsNumeric(Chr(iCodiceTasto)) _
And iCodiceTasto <> 46 Then '46 = punto
iCodiceTasto = 0
Else
If InStr(cContr.Text, ".") > 0 And iCodiceTasto = 46 Then
iCodiceTasto = 0
Else
FiltraTasti = iCodiceTasto
End If
End If
End Function

Questa funzione si richiama nell'evento KeyPress del controllo in
questo modo:
Private Sub txtTesto_KeyPress(KeyAscii As Integer)
KeyAscii = FiltraTasti(txtTesto, KeyAscii, 10)
End Sub


(onlynumbers.html)- by Paolo Puglisi - Modifica del 25/3/2019