Calcolatrice in Visual Basic

Ecco il codice che permette di creare una calcolatrice in Vb. Non vi resta che copiarlo nell’ editor e compilarlo.

Public Class Form1
Dim a, b As Integer
Dim op As Char

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
TextBox1.Text = TextBox1.Text & “1”
End Sub

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
TextBox1.Text = TextBox1.Text & “2”
End Sub

Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
TextBox1.Text = TextBox1.Text & “3”
End Sub

Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
TextBox1.Text = TextBox1.Text & “4”
End Sub

Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click
TextBox1.Text = TextBox1.Text & “5”
End Sub

Private Sub Button6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button6.Click
TextBox1.Text = TextBox1.Text & “6”
End Sub

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

End Sub

Private Sub Button7_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button7.Click
TextBox1.Text = TextBox1.Text & “7”
End Sub

Private Sub Button8_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button8.Click
TextBox1.Text = TextBox1.Text & “8”
End Sub

Private Sub Button9_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button9.Click
TextBox1.Text = TextBox1.Text & “9”
End Sub

Private Sub Button10_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button10.Click
TextBox1.Text = TextBox1.Text & “0”
End Sub

Private Sub Button11_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button11.Click
TextBox1.Text = “"<br />End Sub<br /><br />Private Sub Button13_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button13.Click<br />a = CInt(TextBox1.Text)<br />op = "+"<br />TextBox1.Text = ""<br />End Sub<br /><br />Private Sub Button14_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button14.Click<br />a = CInt(TextBox1.Text)<br />op = "-"<br />TextBox1.Text = ""<br />End Sub<br /><br />Private Sub Button15_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button15.Click<br />a = CInt(TextBox1.Text)<br />op = "/"<br />TextBox1.Text = ""<br />End Sub<br /><br />Private Sub Button16_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button16.Click<br />a = CInt(TextBox1.Text)<br />op = "X"<br />TextBox1.Text = ""<br />End Sub<br /><br />Private Sub Button12_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button12.Click<br />b = CInt(TextBox1.Text)<br />Select Case op<br />Case "+"<br />TextBox1.Text = a + b<br />Case "-"<br />TextBox1.Text = a – b<br />Case "X"<br />TextBox1.Text = a * b<br />Case "/"<br />TextBox1.Text = a / b<br />End Select<br /><br />End Sub<br />End Class”

Lascia un commento

Il tuo indirizzo email non sarà pubblicato.