Red de conocimiento informático - Material del sitio web - Cómo usar VB para hacer una calculadora simple de cuatro aritméticas

Cómo usar VB para hacer una calculadora simple de cuatro aritméticas

Es muy simple: coloque cuatro controles COMMAND en la ventana (las propiedades de los títulos son +, -, X, ÷), tres controles de TEXTO y luego coloque tres controles de etiqueta (las propiedades de los títulos son: Operando 1, Operando 2 y resultado del cálculo), el atributo Título de la ventana se cambia a "Cuatro operaciones aritméticas"

El código es el siguiente:

Private Sub Command1_Click()

Si Val(Text1.Text) + Val(Text2.Text) <> Int(Val(Text1.Text) + Val(Text2.Text)) Entonces

Text3.Text = Format(Val( Texto1 .Texto) + Val(Texto2.Texto), "0.######")

Else

Texto3.Texto = Val(Texto1.Texto) + Val (Text2.Text)

Finalizar si

Finalizar sub

Subcomando privado2_Click()

Si Val(Text1.Text) - Val (Texto2.Text) <> Int(Val(Text1.Text) - Val(Text2.Text)) Entonces

Text3.Text = Formato(Val(Text1.Text) - Val(Text2.Text) ) , "0.######")

Else

Text3.Text = Val(Text1.Text) - Val(Text2.Text)

Finalizar si

End Sub

Subcomando privado3_Click()

Si Val(Text1.Text) * Val(Text2.Text) <> Int( Val (Text1.Text) * Val(Text2.Text)) Luego

Text3.Text = Formato(Val(Text1.Text) * Val(Text2.Text), "0.##### # ")

Else

Text3.Text = Val(Text1.Text) * Val(Text2.Text)

Finalizar si

Finalizar sub

Subcomando privado4_Click()

Si Val(Text1.Text) / Val(Text2.Text) <> Int(Val(Text1.Text) / Val(Text2) . Texto)) Entonces

Texto3.Texto = Formato(Val(Texto1.Texto) / Val(Texto2.Texto), "0.######")

De lo contrario

Text3.Text = Val(Text1.Text) / Val(Text2.Text)

End If

End Sub