View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
Rick Rothstein \(MVP - VB\) Rick Rothstein \(MVP - VB\) is offline
external usenet poster
 
Posts: 2,202
Default I am getting duplicate decimal points on numeric validation

I'm glad you liked it. Since you are planning on using it for your basic
number validation routine, I thought you might like its companion routine
for proofing digits only. I have included the code for it after my
signature. There are no limits to set within the code for this version as
the TextBox itself has a MaxLength property where you can limit the total
number of characters typed in. I used the same TextBox name (Intrate) in
this routine as I did for the floating point one... the TextBox names are
all specified in With statements, so changing them to match your current
TextBox name will be easy enough to do. Oh, if you want to allow your user
to be able to type in a leading plus or minus sign, change this If-Then
statement (in the Change event procedure)...

If .Text Like "*[!0-9]*" Then

to this instead...

If .Text Like "*[!0-9+-]*" Or .Text Like "?*[+-]*" Then

Rick


'For typing digits only in the TextBox
'=====================================
Dim LastPosition As Long

Private Sub Intrate_Change()
Static LastText As String
Static SecondTime As Boolean
If Not SecondTime Then
With Intrate
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 Intrate_MouseDown(ByVal Button As Integer, _
ByVal Shift As Integer, _
ByVal X As Single, _
ByVal Y As Single)
With Intrate
LastPosition = .SelStart
'Place any other MouseDown event code here
End With
End Sub

Private Sub Intrate_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger)
With Intrate
LastPosition = .SelStart
'Place any other KeyPress checking code here
End With
End Sub