No dejar escribir letras en un TextBox
Pues eso,¿c贸mo hago para que no se puedan meter letras y s贸lo me deje meter n煤meros?Si es posible que si intento escribir una letra que no haga nada.
Es con el evento keypress del setfocus,
Private Sub Text1_KeyUp(KeyCode As Integer, Shift As Integer)
Dim Posicion As Integer
If ((KeyCode >= 48 And KeyCode <= 57) Or (KeyCode >= 96 And KeyCode <= 105) Or KeyCode = 8 Or KeyCode = 46) And Shift = False Then
Texto = Text1.Text
Text1.Text = Texto
Else
If KeyCode <> 37 And KeyCode <> 39 And Text1.SelStart <> 0 Then
Posicion = Text1.SelStart
Text1.Text = Texto
Text1.SelStart = Posicion - 1
End If
End If
End Sub
saludos
Private Sub Text1_KeyUp(KeyCode As Integer, Shift As Integer)
Dim Posicion As Integer
If ((KeyCode >= 48 And KeyCode <= 57) Or (KeyCode >= 96 And KeyCode <= 105) Or KeyCode = 8 Or KeyCode = 46) And Shift = False Then
Texto = Text1.Text
Text1.Text = Texto
Else
If KeyCode <> 37 And KeyCode <> 39 And Text1.SelStart <> 0 Then
Posicion = Text1.SelStart
Text1.Text = Texto
Text1.SelStart = Posicion - 1
End If
End If
End Sub
saludos
o mejor:
Private Sub Text1_KeyPress(KeyAscii As Integer)
If KeyAscii <> 8 And KeyAscii <> 9 And KeyAscii <> 13 And KeyAscii <> 46 Then
If KeyAscii < 48 Or KeyAscii > 57 Then KeyAscii = 0
End If
End Sub
saludos
Private Sub Text1_KeyPress(KeyAscii As Integer)
If KeyAscii <> 8 And KeyAscii <> 9 And KeyAscii <> 13 And KeyAscii <> 46 Then
If KeyAscii < 48 Or KeyAscii > 57 Then KeyAscii = 0
End If
End Sub
saludos
