PERMITIR SO NUMEROS EM UMA TEXT
Pessoal, como faço para que na textbox digite só numeros?
'Caso de erro de library ticar em referencias :MICROSOFT DATA FORMATTING OBJECT LIBRARY
'Para chamar a rotina
Private Sub NomeObjeto_KeyPress(KeyAscii As Integer)
KeyAscii = SoNumeros(KeyAscii)
End Sub
'Só Numeros
Public Function SoNumeros(Key As Integer) As Integer
Const Numeros$ = "0123456789"
SoNumeros = Key
If Key <> 8 Then
If InStr(Numeros$, Chr(Key)) = 0 Then
SoNumeros = 0
End If
End If
End Function
'Para chamar a rotina
Private Sub NomeObjeto_KeyPress(KeyAscii As Integer)
KeyAscii = SoNumeros(KeyAscii)
End Sub
'Só Numeros
Public Function SoNumeros(Key As Integer) As Integer
Const Numeros$ = "0123456789"
SoNumeros = Key
If Key <> 8 Then
If InStr(Numeros$, Chr(Key)) = 0 Then
SoNumeros = 0
End If
End If
End Function
Private Sub Text1_KeyPress(KeyAscii As Integer)
Select Case KeyAscii
Case vbKeyDelete, vbKeyBack, vbkeyenter
Case 48 To 57
If Len(Text1.Text) = 2 Or Len(Text1.Text) = 5 Then
Text1.Text = Text1.Text & "/"
End If
Text1.SelStart = Len(Text1.Text)
Case 8, 44
Case Else
KeyAscii = 0
End Select
End Sub
Select Case KeyAscii
Case vbKeyDelete, vbKeyBack, vbkeyenter
Case 48 To 57
If Len(Text1.Text) = 2 Or Len(Text1.Text) = 5 Then
Text1.Text = Text1.Text & "/"
End If
Text1.SelStart = Len(Text1.Text)
Case 8, 44
Case Else
KeyAscii = 0
End Select
End Sub
Tópico encerrado , respostas não são mais permitidas