
06/05/2008, 08:35
|
 | Moderador | | Fecha de Ingreso: abril-2005 Ubicación: In this planet
Mensajes: 15.720
Antigüedad: 20 años Puntos: 839 | |
Re: Ingresar en cuadro de texto solo numeros y signos Coloca este código en el evento KeyPress del TextBox:
Código:
Dim Selected As Integer
If InStr("0123456789", Chr(KeyAscii)) = 0 Then
If InStr("+-", Chr(KeyAscii)) <> 0 Then
If Len(Text1) = 0 Then
Text1 = Chr(KeyAscii)
Else
Dim Text As String
Text = Text1
Mid(Text, 1, 1) = Chr(KeyAscii)
Text1 = Text
End If
End If
If KeyAscii <> 8 Then KeyAscii = 0
Else
If Len(Text1) > 0 Then
Selected = Text1.SelStart
Text1.Tag = Text1.Text
Text1.Text = Left(Text1, Text1.SelStart) & Chr(KeyAscii) & Right(Text1, Len(Text1) - Text1.SelStart)
Text1.Text = Left(Text1, 1) & Format(Right(Text1, Len(Text1) - 1), "#.00")
If Right(Text1, 2) <> "00" And Right(Text1, 2) <> "25" And Right(Text1, 2) <> "50" And Right(Text1, 2) <> "75" Then
Text1.Text = Text1.Tag
Text1.SelStart = Selected
Else
Text1.SelStart = Selected + 1
End If
End If
KeyAscii = 0
End If
Espero que te funcione...
Saludos
Última edición por David; 06/05/2008 a las 08:43
Razón: Agregar código
|