>
http://vbnet.mvps.org/code/textapi/txstyles.htm
Of course, the API function you cite for restricting input to
digits-only suffers from the flaw that allows a user to Paste non-digits
into the TextBox. For those reading this thread, here is a non-API
solution that protects against Pasting too. Paste the following code
into the code window for the form housing the TextBox (assumed to be
named Text1 for this example).
Rick - MVP
Dim LastPosition As Long
Private Sub Text1_Change()
Static LastText As String
Static SecondTime As Boolean
If Not SecondTime Then
With Text1
If .Text Like "*[!0-9]*" Then
Beep
SecondTime = True
.Text = LastText
.SelStart = LastPosition
Else
LastText = .Text
End If
End With
End If
SecondTime = False
End Sub
Private Sub Text1_MouseDown(Button As Integer, _
Shift As Integer, X As Single, Y As Single)
With Text1
LastPosition = .SelStart
'Place any other MouseDown event code here
End With
End Sub
Private Sub Text1_KeyPress(KeyAscii As Integer)
With Text1
LastPosition = .SelStart
'Place any other KeyPress checking code here
End With
End Sub