Visual Basic - Val para tomar valores numericos de un text box

Life is soft - evento anual de software empresarial
 
Vista:

Val para tomar valores numericos de un text box

Publicado por Axel (2 intervenciones) el 15/09/2015 03:43:39
Soy novato en VB6 y me topé con este problema a la hora de hacer un proyecto de calculadora simple.
No logro que la variable numero2 tome los valores que aparecen en el Text.Box. Qué puede ser? Agradezco mucho su ayuda.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
Dim numero1 As Integer
Dim numero2 As Integer
Dim operacion As String
Dim resultado As Integer
 
Private Sub cmd0_Click()
Text1.Text = Text1.Text & "0"
End Sub
 
Private Sub cmd1_Click()
Text1.Text = Text1.Text & "1"
End Sub
 
Private Sub cmd2_Click()
Text1.Text = Text1.Text & "2"
End Sub
 
Private Sub cmd3_Click()
Text1.Text = Text1.Text & "3"
End Sub
 
Private Sub cmd4_Click()
Text1.Text = Text1.Text & "4"
End Sub
 
Private Sub cmd5_Click()
Text1.Text = Text1.Text & "5"
End Sub
 
Private Sub cmd6_Click()
Text1.Text = Text1.Text & "6"
End Sub
 
Private Sub cmd7_Click()
Text1.Text = Text1.Text & "7"
End Sub
 
Private Sub cmd8_Click()
Text1.Text = Text1.Text & "8"
End Sub
 
Private Sub cmd9_Click()
Text1.Text = Text1.Text & "9"
End Sub
 
Private Sub cmdadd_Click()
numero1 = Val(Text1.Text)
Text1.Text = ""
operación = "+"
End Sub
 
Private Sub cmdce_Click()
Text1.Text = ""
End Sub
 
Private Sub cmddivide_Click()
numero1 = Val(Text1.Text)
Text1.Text = ""
operación = "/"
End Sub
 
Private Sub cmdequal_Click()
numero2 = Val(Text1.Text)
If operacion = "+" Then
    resultado = numero1 + numero2
ElseIf operacion = "-" Then
    resultado = numero1 - numero2
ElseIf operacion = "*" Then
    resultado = numero1 * numero2
ElseIf operacion = "/" Then
    resultado = numero1 / numero2
End If
Text1.Text = resultado
End Sub
 
 
Private Sub cmdminus_Click()
numero1 = Val(Text1.Text)
Text1.Text = ""
operación = "-"
End Sub
 
Private Sub cmdmultiply_Click()
numero1 = Val(Text1.Text)
Text1.Text = ""
operación = "*"
End Sub
 
Private Sub cmdpoint_Click()
Text1.Text = "."
End Sub
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
Imágen de perfil de Andres Leonardo
Val: 3.117
Oro
Ha mantenido su posición en Visual Basic (en relación al último mes)
Gráfica de Visual Basic

Val para tomar valores numericos de un text box

Publicado por Andres Leonardo (1798 intervenciones) el 15/09/2015 17:11:57
Hola una consulta por que en el Ecual pones

numero2 = Val(Text1.Text)

Se supone que deberia ser

numero2 = Val(Text2.Text)

Espero te sirva.
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

Val para tomar valores numericos de un text box

Publicado por Axel (2 intervenciones) el 19/09/2015 00:12:21
Hola Andres. Lo que sucede es que la calculadora está compuesta por un solo text box. Como lo de Windows por ejemplo.
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