
Codigo que muestra como crear un textbox que permita el ingreso de números solamente.

Function SoloNumeros(ByVal Keyascii As Short) As Short If InStr("1234567890", Chr(Keyascii)) = 0 Then SoloNumeros = 0 Else SoloNumeros = Keyascii End If Select Case Keyascii Case 8 SoloNumeros = Keyascii Case 13 SoloNumeros = Keyascii End Select End Function ------------------------------------------------------------------------------------------------ Ahora valla al Formulario y haga doble click sobre el: Después de la línea: Inherits System.Windows.Forms.Form Copie y pegue esta Declaración de Variable Public KeyAscii As Short Ahora en el evento KeyPress del textBox1 copie y pegue este código Dim KeyAscii As Short = CShort(Asc(e.KeyChar)) keyascii = CShort(SoloNumeros(keyascii)) If keyascii = 0 Then e.Handled = True End If Quedaría de la siguiente forma: Private Sub TextBox1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox1.KeyPress Dim KeyAscii As Short = CShort(Asc(e.KeyChar)) keyascii = CShort(SoloNumeros(keyascii)) If keyascii = 0 Then e.Handled = True End If End Sub