CODIGO FONTE DE CALCULADORA
Autor: blogger ti | Publicado: 2012-01-21T14:43:00-08:00


Neste exemplo de calculadora em VB.Net, eu montei de uma forma diferente do que é publicado normalmente. Para cada botão criei uma pequena memória, ao qual é manipulado nos cálculos. Além de botões de C, CE, M e M+. Vale a pena conferir e testar

Public Class Form1
&nbsp; &nbsp; Dim A As Integer
&nbsp; &nbsp; Dim B As Integer
&nbsp; &nbsp; Dim C As Integer
&nbsp; &nbsp; Dim D As Integer
&nbsp; &nbsp; Dim L As Integer
&nbsp; &nbsp; Dim F As Integer
&nbsp; &nbsp; Dim G As Integer
&nbsp; &nbsp; Dim H As Integer
&nbsp; &nbsp; Dim I As Integer
&nbsp; &nbsp; Dim J As Integer
&nbsp; &nbsp; Dim K As Integer
&nbsp; &nbsp; Dim Fator As Integer
&nbsp; &nbsp; Dim Val As Integer
&nbsp; &nbsp; Dim Memoria As Integer

&nbsp; &nbsp; Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

&nbsp; &nbsp; End Sub

&nbsp; &nbsp; Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged
&nbsp; &nbsp; End Sub

&nbsp; &nbsp; Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
&nbsp; &nbsp; &nbsp; &nbsp; If (TextBox1.Text &lt;&gt; 0) Then
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; A = (TextBox1.Text)
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; B = (1)
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; TextBox1.Text = (A &amp; B)
&nbsp; &nbsp; &nbsp; &nbsp; End If
&nbsp; &nbsp; &nbsp; &nbsp; If (TextBox1.Text = 0) Then
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; B = (1)
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; TextBox1.Text = (B)
&nbsp; &nbsp; &nbsp; &nbsp; End If
&nbsp; &nbsp; End Sub

&nbsp; &nbsp; Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
&nbsp; &nbsp; &nbsp; &nbsp; If (TextBox1.Text &lt;&gt; 0) Then
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; A = (TextBox1.Text)
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; C = (2)
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; TextBox1.Text = (A &amp; C)
&nbsp; &nbsp; &nbsp; &nbsp; End If
&nbsp; &nbsp; &nbsp; &nbsp; If (TextBox1.Text = 0) Then
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; C = (2)
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; TextBox1.Text = (C)
&nbsp; &nbsp; &nbsp; &nbsp; End If
&nbsp; &nbsp; End Sub

&nbsp; &nbsp; Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
&nbsp; &nbsp; &nbsp; &nbsp; If (TextBox1.Text &lt;&gt; 0) Then
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; A = (TextBox1.Text)
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; D = (3)
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; TextBox1.Text = (A &amp; D)
&nbsp; &nbsp; &nbsp; &nbsp; End If
&nbsp; &nbsp; &nbsp; &nbsp; If (TextBox1.Text = 0) Then
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; D = (3)
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; TextBox1.Text = (D)
&nbsp; &nbsp; &nbsp; &nbsp; End If
&nbsp; &nbsp; End Sub

&nbsp; &nbsp; Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click
&nbsp; &nbsp; &nbsp; &nbsp; If (TextBox1.Text &lt;&gt; 0) Then
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; A = (TextBox1.Text)
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; L = (4)
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; TextBox1.Text = (A &amp; L)
&nbsp; &nbsp; &nbsp; &nbsp; End If
&nbsp; &nbsp; &nbsp; &nbsp; If (TextBox1.Text = 0) Then
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; L = (4)
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; TextBox1.Text = (L)
&nbsp; &nbsp; &nbsp; &nbsp; End If
&nbsp; &nbsp; End Sub

&nbsp; &nbsp; Private Sub Button6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button6.Click
&nbsp; &nbsp; &nbsp; &nbsp; If (TextBox1.Text &lt;&gt; 0) Then
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; A = (TextBox1.Text)
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; F = (5)
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; TextBox1.Text = (A &amp; F)
&nbsp; &nbsp; &nbsp; &nbsp; End If
&nbsp; &nbsp; &nbsp; &nbsp; If (TextBox1.Text = 0) Then
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; F = (5)
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; TextBox1.Text = (F)
&nbsp; &nbsp; &nbsp; &nbsp; End If
&nbsp; &nbsp; End Sub

&nbsp; &nbsp; Private Sub Button7_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button7.Click
&nbsp; &nbsp; &nbsp; &nbsp; If (TextBox1.Text &lt;&gt; 0) Then
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; A = (TextBox1.Text)
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; G = (6)
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; TextBox1.Text = (A &amp; G)
&nbsp; &nbsp; &nbsp; &nbsp; End If
&nbsp; &nbsp; &nbsp; &nbsp; If (TextBox1.Text = 0) Then
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; G = (6)
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; TextBox1.Text = (G)
&nbsp; &nbsp; &nbsp; &nbsp; End If
&nbsp; &nbsp; End Sub

&nbsp; &nbsp; Private Sub Button9_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button9.Click
&nbsp; &nbsp; &nbsp; &nbsp; If (TextBox1.Text &lt;&gt; 0) Then
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; A = (TextBox1.Text)
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; H = (7)
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; TextBox1.Text = (A &amp; H)
&nbsp; &nbsp; &nbsp; &nbsp; End If
&nbsp; &nbsp; &nbsp; &nbsp; If (TextBox1.Text = 0) Then
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; H = (7)
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; TextBox1.Text = (H)
&nbsp; &nbsp; &nbsp; &nbsp; End If
&nbsp; &nbsp; End Sub

&nbsp; &nbsp; Private Sub Button10_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button10.Click
&nbsp; &nbsp; &nbsp; &nbsp; If (TextBox1.Text &lt;&gt; 0) Then
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; A = (TextBox1.Text)
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; I = (8)
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; TextBox1.Text = (A &amp; I)
&nbsp; &nbsp; &nbsp; &nbsp; End If
&nbsp; &nbsp; &nbsp; &nbsp; If (TextBox1.Text = 0) Then
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; I = (8)
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; TextBox1.Text = (I)
&nbsp; &nbsp; &nbsp; &nbsp; End If
&nbsp; &nbsp; End Sub

&nbsp; &nbsp; Private Sub Button11_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button11.Click
&nbsp; &nbsp; &nbsp; &nbsp; If (TextBox1.Text &lt;&gt; 0) Then
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; A = (TextBox1.Text)
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; J = (9)
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; TextBox1.Text = (A &amp; J)
&nbsp; &nbsp; &nbsp; &nbsp; End If
&nbsp; &nbsp; &nbsp; &nbsp; If (TextBox1.Text = 0) Then
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; J = (9)
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; TextBox1.Text = (J)
&nbsp; &nbsp; &nbsp; &nbsp; End If
&nbsp; &nbsp; End Sub

&nbsp; &nbsp; Private Sub Button13_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button13.Click
&nbsp; &nbsp; &nbsp; &nbsp; If (TextBox1.Text &lt;&gt; 0) Then
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; A = (TextBox1.Text)
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; K = (0)
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; TextBox1.Text = (A &amp; K)
&nbsp; &nbsp; &nbsp; &nbsp; End If
&nbsp; &nbsp; &nbsp; &nbsp; If (TextBox1.Text = 0) Then
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; K = (0)
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; TextBox1.Text = (K)
&nbsp; &nbsp; &nbsp; &nbsp; End If
&nbsp; &nbsp; End Sub

&nbsp; &nbsp; Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
&nbsp; &nbsp; &nbsp; &nbsp; Val = (TextBox1.Text)
&nbsp; &nbsp; &nbsp; &nbsp; TextBox1.Text = (0)
&nbsp; &nbsp; &nbsp; &nbsp; Fator = (1)
&nbsp; &nbsp; End Sub

&nbsp; &nbsp; Private Sub Button8_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button8.Click
&nbsp; &nbsp; &nbsp; &nbsp; Val = (TextBox1.Text)
&nbsp; &nbsp; &nbsp; &nbsp; TextBox1.Text = (0)
&nbsp; &nbsp; &nbsp; &nbsp; Fator = (2)
&nbsp; &nbsp; End Sub

&nbsp; &nbsp; Private Sub Button12_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button12.Click
&nbsp; &nbsp; &nbsp; &nbsp; Val = (TextBox1.Text)
&nbsp; &nbsp; &nbsp; &nbsp; TextBox1.Text = (0)
&nbsp; &nbsp; &nbsp; &nbsp; Fator = (3)
&nbsp; &nbsp; End Sub

&nbsp; &nbsp; Private Sub Button14_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button14.Click
&nbsp; &nbsp; &nbsp; &nbsp; Val = (TextBox1.Text)
&nbsp; &nbsp; &nbsp; &nbsp; TextBox1.Text = (0)
&nbsp; &nbsp; &nbsp; &nbsp; Fator = (4)
&nbsp; &nbsp; End Sub

&nbsp; &nbsp; Private Sub Button15_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button15.Click
&nbsp; &nbsp; &nbsp; &nbsp; If (Fator = 1) Then
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; A = ((Val) + (TextBox1.Text))
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; TextBox1.Text = (A)
&nbsp; &nbsp; &nbsp; &nbsp; End If
&nbsp; &nbsp; &nbsp; &nbsp; If (Fator = 2) Then
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; A = ((Val) - (TextBox1.Text))
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; TextBox1.Text = (A)
&nbsp; &nbsp; &nbsp; &nbsp; End If
&nbsp; &nbsp; &nbsp; &nbsp; If (Fator = 3) Then
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; A = ((Val) * (TextBox1.Text))
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; TextBox1.Text = (A)
&nbsp; &nbsp; &nbsp; &nbsp; End If
&nbsp; &nbsp; &nbsp; &nbsp; If (Fator = 4) Then
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; A = ((Val) / (TextBox1.Text))
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; TextBox1.Text = (A)
&nbsp; &nbsp; &nbsp; &nbsp; End If
&nbsp; &nbsp; End Sub

&nbsp; &nbsp; Private Sub Button16_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button16.Click
&nbsp; &nbsp; &nbsp; &nbsp; TextBox1.Text = (0)
&nbsp; &nbsp; &nbsp; &nbsp; A = (0)
&nbsp; &nbsp; &nbsp; &nbsp; Fator = (0)
&nbsp; &nbsp; End Sub

&nbsp; &nbsp; Private Sub Button18_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button18.Click
&nbsp; &nbsp; &nbsp; &nbsp; TextBox1.Text = (0)
&nbsp; &nbsp; End Sub

&nbsp; &nbsp; Private Sub Button19_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button19.Click
&nbsp; &nbsp; &nbsp; &nbsp; Memoria = (TextBox1.Text)
&nbsp; &nbsp; End Sub

&nbsp; &nbsp; Private Sub Button17_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button17.Click
&nbsp; &nbsp; &nbsp; &nbsp; TextBox1.Text = (Memoria)
&nbsp; &nbsp; End Sub
End Class

imagens da calculadora...






obs: falta estanciar os comando para que o teclado numerico seja reconhecido...mais este&nbsp;código&nbsp;esta muito bom...



por enquanto e&nbsp;só&nbsp;...ate a&nbsp;próxima...