Visual Basic - DUDA PLEASE!!SOLO NUMERO Y EL 0???

Life is soft - evento anual de software empresarial
 
Vista:

DUDA PLEASE!!SOLO NUMERO Y EL 0???

Publicado por EDGAR (193 intervenciones) el 09/02/2005 23:14:00
DUDA PLEASE!!SOLO NUMERO Y EL 0???

Hola colega, tengo un gran problemilla ya que estoy realizando una rutina en mis textbox para que me admita solo numeros pero resulta que no me admite el numero 0 al inicio sino a partir del segundo caracter. La rutina es la siguiente:
Private Sub TXTcedula1_KeyPress(KeyAscii As Integer)
Dim strNumeros As String
strNumeros = "1234567890" & Chr(8)
If Len(TXTcedula1) = 0 And Chr(KeyAscii) = 0 Then
KeyAscii = 0
Else
If InStr(1, strNumeros, Chr(KeyAscii), vbBinaryCompare) = 0 Then
KeyAscii = 0
End If
End If
End Sub

Agradezco de tu ayuda para ver en que estoy fallando.. Gracias
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:DUDA PLEASE!!SOLO NUMERO Y EL 0???

Publicado por jlcastro (186 intervenciones) el 09/02/2005 23:54:14
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
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

RE:DUDA PLEASE!!SOLO NUMERO Y EL 0???

Publicado por Oliver Kraft (25 intervenciones) el 10/02/2005 01:42:04
mira, estas instrucciones te puedev servir...

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
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