Variáveis globais:
Public Class Form1
Dim operador As String
Dim num1 As Double
Dim num2 As Double
Adicione 17 botões e um TextBox
TextBox1 - Name:
txtCalcular
Botão 1 - Código:
txtCalcular.Text += "1"
Botão 2 - Código:
txtCalcular.Text += "2"
Botão 3 - Código:
txtCalcular.Text += "3"
Botão 4 - Código:
txtCalcular.Text += "4"
Botão 5 - Código:
txtCalcular.Text += "5"
Botão 6 - Código:
txtCalcular.Text += "6"
Botão 7 - Código:
txtCalcular.Text += "7"
Botão 8 - Código:
txtCalcular.Text += "8"
Botão 9 - Código:
txtCalcular.Text += "9"
Botão 0 - Código:
txtCalcular.Text += "0"
.................................................................................
Botão Limpar - Código:
txtCalcular.Text = ""
.................................................................................
Botão , Código:
txtCalcular.Text += ","
.................................................................................
Botão + Código:
If txtCalcular.Text = "" Then
MsgBox("Coloque um dígito!")
Else
num1 = txtCalcular.Text
operador = "+"
txtCalcular.Text = ""
End If
.................................................................................
Botão - Código:
If txtCalcular.Text = "" Then
MsgBox("Coloque um dígito!")
Else
num1 = txtCalcular.Text
operador = "-"
txtCalcular.Text = ""
End If
.................................................................................
Botão / Código:
If txtCalcular.Text = "" Then
MsgBox("Coloque um dígito!")
Else
num1 = txtCalcular.Text
operador = "/"
txtCalcular.Text = ""
End If
.................................................................................
Botão x Código:
If txtCalcular.Text = "" Then
MsgBox("Coloque um dígito!")
Else
num1 = txtCalcular.Text
operador = "x"
txtCalcular.Text = ""
End If
.................................................................................
Botão = Código:
If txtCalcular.Text = "" Then
MsgBox("Coloque um dígito!")
Else
num2 = txtCalcular.Text
If operador = "x" Then 'Multiplicar
txtCalcular.Text = num1 * num2
End If
If operador = "+" Then 'Somar
txtCalcular.Text = num1 + num2
End If
If operador = "-" Then 'Subtrair
txtCalcular.Text = num1 - num2
End If
If operador = "/" Then 'Dividir
txtCalcular.Text = num1 / num2
End If
End If
Muito útel. obrigado
ResponderExcluir