SOLO NUMEROS
Sub Text1_Keypress(KeyAscii As Integer)
If KeyAscii > Asc("9") Then
'KeyAscii = 8 es el retroceso o BackSpace
If KeyAscii <> 8 Then
KeyAscii = 0
End If
End If
End Sub
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
SOLO NUMEROS Y COMA
Private Sub Text1_KeyPress(KeyAscii As Integer)
If KeyAscii <> 44 And (IsNumeric(Chr(KeyAscii))) = False And KeyAscii <> 8 Then
KeyAscii = 0 ' solo admite numeros y coma
Beep 'Sonido de error de entradaEnd If
End If
End Sub
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
EL PUNTO Y LA COMA (CUALQUIERA DE LOS DOS)
En el formulario declara:
Dim DecimalPoint As Boolean
'Para cada Text box númerico:
Private Sub Text1_KeyDown(KeyCode As Integer, Shift As Integer)
DecimalPoint = (KeyCode = vbKeyDecimal)
End Sub
Private Sub Text1_KeyPress(KeyAscii As Integer)
If DecimalPoint Then
KeyAscii = Asc(Mid(Format(0, "0.0"), 2))
End If
End Sub
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
SOLO LETRAS
Private Sub txtLetras_KeyPress(KeyAscii As Integer)
Select Case KeyAscii
Case 65 To 122
KeyAscii = Asc(UCase(Chr(KeyAscii)))
Case Else
KeyAscii = 0
End Select
End Sub
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
OTRO DE SOLO LETRAS
SOLO LETRAS
Function SOLOLETRAS(keyascii as integer) as integer
If InStr("0123456789", Chr(keyascii)) <> 0 Then
keyascii=0
end if
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
SOLO NUMEROS, RETROCESO Y ENTER
Private Sub Text1_KeyPress(KeyAscii As Integer)
KeyAscii = SoloNumeros(KeyAscii)
End Sub
Function SoloNumeros(ByVal KeyAscii As Integer) As Integer
'permite que solo sean ingresados los numeros, el ENTER y el RETROCESO
If InStr("0123456789/-", Chr(KeyAscii)) = 0 Then
SoloNumeros = 0
Else
SoloNumeros = KeyAscii
End If
' teclas especiales permitidas
If KeyAscii = 8 Then SoloNumeros = KeyAscii ' borrado atras
If KeyAscii = 13 Then SoloNumeros = KeyAscii 'Enter
End Function
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX