Introducir solo números ami calculadora en vb

Quisiera saber si me pueden ayudar en esto estoy haciendo una calculadora en visual basic 6.0 y no encuentro la forma de introducir los números que tengo en la calculadora por medio del teclado dela compu, osea intrucir solo nmeros desde ya

1 Respuesta

Respuesta
1
Lo puede hacer de la siguiente manera, utilizando el evento KeyPress del Texbox de la calculadora, esto hace que solo acepte los dígitos, el signo negativo y el punto decimal.
Private Sub Txnumero_KeyPress(KeyAscii As Integer)
    Select Case KeyAscii
        Case 48 To 57              ' Permite los dígitos
        Case 45 To 46              ' Permite - y .
        Case 8                          ' Permite el carácter de retroceso
        Case Else
            KeyAscii = 0
            Beep
   End Select
End Sub 
Para que lo anterior funcione la propiedad KeyPreview del formulario debe ser True.
Suerte !
Hola kapo gracias por tu ayuda pero necesito algo más especifico mira acá te mando mi código si lo quieres revisar haber donde esta mis errores y me podes ayudar te lo voy a agradecer por que estoy hace como 2 semanas tratando de terminar este trabajo... ahí te va desde ya gracias
Es algo sencillo solo tiene funciones básicas !
Dim num1 As Double
Dim resul As Double
Dim oper As String
Private Function comprobar() As Boolean
If Len(cajadetexto.Text) < 12 Then
comprobar = True
Else
comprobar = False
End If
End Function
Private Function Verificar() As Boolean
End Function
Private Sub borrar_Click()
num1 = 0
resul = "0"
cajadetexto.Text = resul
oper = ""
End Sub
Private Sub cajadetexto_KeyPress(KeyAscii As Integer)
Select Case KeyAscii
Case 48
Call cmd0_Click
Case 49
Call cmd1_Click
Case 45
Call resta_Click
Case Else
KeyAscii = 0
Beep
End Select
End Sub
Private Sub cmd0_Click()
If comprobar Then
cajadetexto.Text = cajadetexto.Text & "0"
Else
cajadetexto.Text = cajadetexto.Text
End If
End Sub
Private Sub cmd1_Click()
' si en la caja de texto tengo un cero borro el cero para que entre el valor del boton'
If cajadetexto.Text = "0" Then
cajadetexto.Text = ""
End If
If comprobar Then
cajadetexto.Text = cajadetexto.Text & "1"
Else
cajadetexto.Text = cajadetexto.Text
End If
End Sub
Private Sub cmd2_Click()
If cajadetexto.Text = "0" Then
cajadetexto.Text = ""
End If
If comprobar Then
cajadetexto.Text = cajadetexto.Text & "2"
Else
cajadetexto.Text = cajadetexto.Text
End If
End Sub
Private Sub cmd3_Click()
If cajadetexto.Text = "0" Then
cajadetexto.Text = ""
End If
If comprobar Then
cajadetexto.Text = cajadetexto.Text & "3"
Else
cajadetexto.Text = cajadetexto.Text
End If
End Sub
Private Sub cmd4_Click()
If cajadetexto.Text = "0" Then
cajadetexto.Text = ""
End If
If comprobar Then
cajadetexto.Text = cajadetexto.Text & "4"
Else
cajadetexto.Text = cajadetexto.Text
End If
End Sub
Private Sub cmd5_Click()
If cajadetexto.Text = "0" Then
cajadetexto.Text = ""
End If
If comprobar Then
cajadetexto.Text = cajadetexto.Text & "5"
Else
cajadetexto.Text = cajadetexto.Text
End If
End Sub
Private Sub cmd6_Click()
If cajadetexto.Text = "0" Then
cajadetexto.Text = ""
End If
If comprobar Then
cajadetexto.Text = cajadetexto.Text & "6"
Else
cajadetexto.Text = cajadetexto.Text
End If
End Sub
Private Sub cmd7_Click()
If cajadetexto.Text = "0" Then
cajadetexto.Text = ""
End If
If comprobar Then
cajadetexto.Text = cajadetexto.Text & "7"
Else
cajadetexto.Text = cajadetexto.Text
End If
End Sub
Private Sub cmd8_Click()
If cajadetexto.Text = "0" Then
cajadetexto.Text = ""
End If
If comprobar Then
cajadetexto.Text = cajadetexto.Text & "8"
Else
cajadetexto.Text = cajadetexto.Text
End If
End Sub
Private Sub cmd9_Click()
If cajadetexto.Text = "0" Then
cajadetexto.Text = ""
End If
If comprobar Then
cajadetexto.Text = cajadetexto.Text & "9"
Else
cajadetexto.Text = cajadetexto.Text
End If
End Sub
Private Sub signo_Click()
If cajadetexto.Text = "-" Then
cajadetexto.Text = cajadetexto.Text
Else
cajadetexto.Text = "-" & cajadetexto.Text
End If
End Sub
Private Sub div_Click()
If cajadetexto.Text = "" Then
cajadetexto.Text = "0"
End If
If (num1 <> 0) Then
resul = num1 / cajadetexto.Text
cajadetexto.Text = resul
End If
num1 = cajadetexto.Text
cajadetexto.Text = "0"
oper = "/"
End Sub
Private Sub igual_Click()
If oper = "+" Then
resul = num1 + cajadetexto.Text
num1 = 0
oper = ""
End If
If oper = "-" Then
resul = num1 - cajadetexto.Text
num1 = 0
oper = ""
End If
If oper = "*" Then
resul = num1 * cajadetexto.Text
num1 = 0
oper = ""
End If
If oper = "/" Then
resul = num1 / cajadetexto.Text
num1 = 0
oper = ""
End If
cajadetexto.Text = resul
End Sub
Private Sub mult_Click()
If cajadetexto.Text = "" Then
cajadetexto.Text = "0"
End If
If (num1 <> 0) Then
resul = num1 * cajadetexto.Text
cajadetexto.Text = resul
End If
num1 = cajadetexto.Text
cajadetexto.Text = "0"
oper = "*"
End Sub
Private Sub punto_Click()
cajadetexto.Text = cajadetexto.Text & ","
End Sub
Private Sub resta_Click()
If cajadetexto.Text = "" Then
cajadetexto.Text = "0"
End If
If (num1 <> 0) Then
resul = num1 - cajadetexto.Text
cajadetetxto.Text = resul
End If
num1 = cajadetexto.Text
cajadetexto.Text = "0"
oper = "-"
End Sub
Private Sub sumar_Click()
If cajadetexto.Text = "" Then
cajadetexto.Text = "0"
End If
If (num1 <> 0) Then
resul = num1 + cajadetexto.Text
cajadetexto.Text = resul
End If
num1 = cajadetexto.Text
cajadetexto.Text = "0"
oper = "+"
End Sub

Añade tu respuesta

Haz clic para o

Más respuestas relacionadas