Visual Basic - Suma, Resta, Multiplicacion y Division de decimales en Vb6

Life is soft - evento anual de software empresarial
 
Vista:

Suma, Resta, Multiplicacion y Division de decimales en Vb6

Publicado por Vicente (2 intervenciones) el 23/08/2023 22:38:38
Hola quiero preguntar de como puedo Sumar, Restra, Multiplicar y Dividir numeros en mi calculadora de vb6.
Aca les dejo todo mi codigo de todos los botones de la calculadora:
Porfavor ayudenme

Dim num1 As Integer
Dim num2 As Integer
Dim op As String
Dim acum As Double


Private Sub BotonDIVIDIR_Click()
num1 = CDbl(Text1.Text)
Text1.Text = ""
op = "/"
Text1.SetFocus
End Sub

Private Sub BotonIGUAL_Click()
If (num1 = 0) Then
MsgBox ("No se realizó ninguna operación")
Else
num2 = CDbl(Text1.Text)
If op = "+" Then
Text1.Text = acum + num1
ElseIf op = "-" Then
Text1.Text = num1 - num2
ElseIf op = "*" Then
Text1.Text = acum * num1
ElseIf op = "/" Then
If num2 <> 0 Then
Text1.Text = num1 / num2
Else
MsgBox ("No se puede dividir por cero")
End If
End If
End If
End Sub

Private Sub BotonMAS_Click()
num1 = CDbl(Text1.Text)
Text1.Text = ""
op = "+"
acum = acum + num1
Text1.SetFocus
End Sub

Private Sub BotonMENOS_Click()
num1 = CDbl(Text1.Text)
Text1.Text = ""
op = "-"
Text1.SetFocus
End Sub

Private Sub BotonMULTIPLICAR_Click()
num1 = CDbl(Text1.Text)
Text1.Text = ""
op = "*"
acum = acum * num1
Text1.SetFocus
End Sub

Private Sub Command10_Click()
Text1.Text = Text1.Text & 0
End Sub

Private Sub Command11_Click()
Text1.Text = Text1.Text & 8
End Sub

Private Sub Command12_Click()
Text1.Text = Text1.Text & 5
End Sub

Private Sub Command13_Click()
Text1.Text = ""
acum = 0
Text1.SetFocus
End Sub

Private Sub Command14_Click()
Text1.Text = Text1.Text & 6
End Sub

Private Sub Command15_Click()
Text1.Text = Text1.Text & 9
End Sub

Private Sub Command17_Click()
Text1.Text = Text1.Text & 3
End Sub

Private Sub Command24_Click()

End Sub

Private Sub Command18_Click()
Text1.Text = Text1.Text & (".")
End Sub

Private Sub Command3_Click()
Text1.Text = Text1.Text & 7
End Sub

Private Sub Command4_Click()
Text1.Text = Text1.Text & 4
End Sub

Private Sub Command5_Click()
Text1.Text = Text1.Text & 1
End Sub

Private Sub Command7_Click()
Text1.Text = ""
Text1.SetFocus
End Sub

Private Sub Command9_Click()
Text1.Text = Text1.Text & 2
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

Suma, Resta, Multiplicacion y Division de decimales en Vb6

Publicado por 5ah1d ra Gutierrez Cruz (6 intervenciones) el 28/08/2023 23:46:16
Hola!!!

Cambia esto
1
2
Dim num1 As Integer
Dim num2 As Integer

por esto
1
2
Dim num1 As Double
Dim num2 As Double

y asi poder usar la funcion correctamente CDbl

y a mi gusto para el control de los botones utiliza
indices y en el caption utiliza el valor que usaran.

y si usas los indices puedes hacer lo siguiente:

1
2
3
Private Sub Command1_Click(Index as integer)
 Text1.Text = Text1.Text & command1(index).Caption
End Sub

y en el Load_Form hacer algo asi
1
2
3
4
5
6
7
8
9
10
11
12
13
Dim Tempo as integer
   For Tempo = 0 To 9
      If Tempo >0 Then Load Command1(Tempo)
      Command1(Tempo).Visible = True
      Command1(Tempo).Caption = cStr(Tempo)
      if tempo mod 3 then
         command1(tempo).left= command1(tempo-3).left
         command1(tempo).top = command1(tempo-3).top +command1(tempo).height
      else
         command1(tempo).left= command1(tempo-1).left  +command1(tempo).width
         command1(tempo).top = command1(tempo-1).top +command1(tempo).height
      end if
   next tempo


algo asi quedaria, solo checa algunas sintaxis o cosillas
pero la idea asi es, para los simbolos es algo muy
parecido puedes usar el codigo ascci desde el 42 hasta el 57


saludos y felices lineas e programac1ón
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