Visual Basic - Ayuda con un text box

Life is soft - evento anual de software empresarial
 
Vista:

Ayuda con un text box

Publicado por crisitan Bianciotto (3 intervenciones) el 03/01/2006 18:37:22
Alguien me podria decir como hago para que en un text box pueda ingresar solo numeros , solo letras o numeros y letras todo con el mismo codigo?
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder

RE:Ayuda con un text box

Publicado por jlcastro (186 intervenciones) el 03/01/2006 18:55:47
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
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar