Hola
Tengo una duda, como puedo hacer que un text acepte solo numeros y no letras, osea solo numeros, cualquier informacion será bienvenida.
Salu2
Con esto solo te permite poner los numeros en el textbox llamado Text1
--------------------------------------------------------------------------
Private Sub Text1_KeyPress(KeyAscii As Integer)
If InStr("0123456789", Chr(KeyAscii)) = 0 And KeyAscii <> 8 Then
KeyAscii = 0
End If
End Sub
--------------------------------------------------------------------------
Si queres que perimita algun caracter como un punto o lo que quieras solo agregalo a donde dice InfStr"0123456789." listo hay solo te acepta numeros y un punto.
espero que te sirva. ;D
Esta forma la uso yo en casillas donde solo pueden haber numeros enteros. En caso de que se escriba cualquier otra cosa su valor cambia a cero y asi no da problemas con operaciones matematicas etc....
Private Sub Text1_Change()
If Not Text1.Text = Int(Text1.Text) Then
Text1.Text = "0"
End if
End Sub
Espero que te sirva tambien!
existe una funcion llamada isnumeric() que sirve para estos casos
Private Sub Text1_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 Then 'enter
Exit Sub
End If
If KeyAscii = 8 Then 'backspace
Exit Sub
End If
If Not IsNumeric(Chr(KeyAscii)) Then
KeyAscii = 0 'anular tecla
End If
End Sub
Muy buena idea ;),
Cita de: UTU en 28 Febrero 2006, 22:27 PM
Con esto solo te permite poner los numeros en el textbox llamado Text1
--------------------------------------------------------------------------
Private Sub Text1_KeyPress(KeyAscii As Integer)
If InStr("0123456789", Chr(KeyAscii)) = 0 And KeyAscii <> 8 Then
KeyAscii = 0
End If
End Sub
--------------------------------------------------------------------------
y si quiero que kontenga solo letras y numeros nada mas.. debo hacerlo de esta forma??
Private Sub Text1_KeyPress(KeyAscii As Integer)
If InStr("0123456789abcdefghiJKLM...etc", Chr(KeyAscii)) = 0 And KeyAscii <> 8 Then
KeyAscii = 0
End If
End Sub
?? Salu2
para que solo acepte letras y numeros puedes hacer algo asi:
Private Sub Text1_KeyPress(KeyAscii As Integer)
If Chr(KeyAscii) Like "[!a-z-0-9]" Then
KeyAscii = 0
End If
End Sub
no necesitas escribir cada caracter.
Hola a to2
Gracias por su aportacion, es muy buena
Salu2
Private Sub txtData_LostFocus()
If Not IsNumeric(txtData) Then
Call MsgBox("Tenés que ingresar un valor numérico", vbExclamation)
txtData = vbNullString
End If
End Sub